Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 182019 Details for
Bug 328775
[compiler] Compiler fails to warn about invalid cast when using J2SE 1.4 compiler settings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch with test
patch.txt (text/plain), 8.68 KB, created by
Srikanth Sankaran
on 2010-10-29 04:21:47 EDT
(
hide
)
Description:
Patch with test
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2010-10-29 04:21:47 EDT
Size:
8.68 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java,v >retrieving revision 1.125 >diff -u -r1.125 BinaryTypeBinding.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java 20 Oct 2010 05:46:47 -0000 1.125 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java 29 Oct 2010 08:18:43 -0000 >@@ -489,7 +489,7 @@ > } else { > methodModifiers |= ExtraCompilerModifiers.AccGenericSignature; > // MethodTypeSignature = ParameterPart(optional) '(' TypeSignatures ')' return_typeSignature ['^' TypeSignature (optional)] >- SignatureWrapper wrapper = new SignatureWrapper(methodSignature, use15specifics); >+ SignatureWrapper wrapper = new SignatureWrapper(methodSignature, true); > if (wrapper.signature[wrapper.start] == '<') { > // <A::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TA;>;)TA; > // ParameterPart = '<' ParameterSignature(s) '>' >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v >retrieving revision 1.374 >diff -u -r1.374 Scope.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 20 Oct 2010 05:46:47 -0000 1.374 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 29 Oct 2010 08:18:50 -0000 >@@ -525,6 +525,7 @@ > return null; // incompatible > > if (typeVariables != Binding.NO_TYPE_VARIABLES) { // generic method >+ boolean compliant14 = compilerOptions().complianceLevel < ClassFileConstants.JDK1_5; > TypeBinding[] newArgs = null; > for (int i = 0; i < argLength; i++) { > TypeBinding param = i < paramLength ? parameters[i] : parameters[paramLength - 1]; >@@ -534,6 +535,26 @@ > System.arraycopy(arguments, 0, newArgs, 0, argLength); > } > newArgs[i] = environment().computeBoxingType(arguments[i]); >+ } else if (compliant14 && invocationSite instanceof MessageSend >+ && param.kind() == Binding.PARAMETERIZED_TYPE && param.erasure().id == TypeIds.T_JavaLangClass >+ && ((ParameterizedTypeBinding) param).arguments.length == 1 >+ && ((ParameterizedTypeBinding) param).arguments[0] instanceof TypeVariableBinding >+ && arguments[i] instanceof BinaryTypeBinding && arguments[i].erasure().id == TypeIds.T_JavaLangClass) { >+ /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=328775. Class literals are special in that >+ they carry (and are the only expressions that can carry) full parameterization information >+ even in 1.4 source code. For inference during method selection/invocation to work properly, >+ resolve class literal expression's type to be a parameterized type if in 1.4 we encounter >+ a method that expects a parameter of the type Class<> >+ */ >+ if (newArgs == null) { >+ newArgs = new TypeBinding[argLength]; >+ System.arraycopy(arguments, 0, newArgs, 0, argLength); >+ } >+ ClassLiteralAccess classLiteral = (ClassLiteralAccess) ((MessageSend) invocationSite).arguments[i]; >+ // Integer.class --> Class<Integer>, perform boxing of base types (int.class --> Class<Integer>) >+ // BundleWiring.class --> Class<BundleWiring> >+ TypeBinding boxedType = boxing(classLiteral.targetType); >+ newArgs[i] = classLiteral.resolvedType = environment().createParameterizedType(((ParameterizedTypeBinding)param).genericType(), new TypeBinding[]{ boxedType }, null /*not a member*/); > } > } > if (newArgs != null) >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v >retrieving revision 1.216 >diff -u -r1.216 BatchCompilerTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 22 Oct 2010 22:42:32 -0000 1.216 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 29 Oct 2010 08:19:00 -0000 >@@ -11861,4 +11861,106 @@ > System.setProperty("user.dir", javaUserDir); > } > } >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328775 - Compiler fails to warn about invalid cast in 1.4 mode. >+public void testInferenceIn14Project(){ >+ String currentWorkingDirectoryPath = System.getProperty("user.dir"); >+ if (currentWorkingDirectoryPath == null) { >+ fail("BatchCompilerTest#testInference14 could not access the current working directory " + currentWorkingDirectoryPath); >+ } else if (!new File(currentWorkingDirectoryPath).isDirectory()) { >+ fail("BatchCompilerTest#testInference14 current working directory is not a directory " + currentWorkingDirectoryPath); >+ } >+ String lib1Path = currentWorkingDirectoryPath + File.separator + "lib1.jar"; >+ try { >+ Util.createJar( >+ new String[] { >+ "Bundle.java", >+ "public class Bundle {\n" + >+ " static <A> A adapt(Class<A> type) {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}" >+ }, >+ null, >+ lib1Path, >+ JavaCore.VERSION_1_5); >+ this.runNegativeTest( >+ new String[] { >+ "src/X.java", >+ "public class X {\n" + >+ " Bundle b = Bundle.adapt(BundleWiring.class);\n" + >+ "}\n" + >+ "class BundleWiring {}\n", >+ }, >+ "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" >+ + " -cp lib1.jar" // relative >+ + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" >+ + " -1.4 -g -preserveAllLocals" >+ + " -proceedOnError -referenceInfo" >+ + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", >+ "", >+ "----------\n" + >+ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 2)\n" + >+ " Bundle b = Bundle.adapt(BundleWiring.class);\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from BundleWiring to Bundle\n" + >+ "----------\n" + >+ "1 problem (1 error)", >+ true); >+ } catch (IOException e) { >+ System.err.println("BatchCompilerTest#testInference14 could not write to current working directory " + currentWorkingDirectoryPath); >+ } finally { >+ new File(lib1Path).delete(); >+ } >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328775 - Compiler fails to warn about invalid cast in 1.4 mode. >+public void testInferenceIn15Project(){ // ensure 1.5 complains too >+ String currentWorkingDirectoryPath = System.getProperty("user.dir"); >+ if (currentWorkingDirectoryPath == null) { >+ fail("BatchCompilerTest#testInference14 could not access the current working directory " + currentWorkingDirectoryPath); >+ } else if (!new File(currentWorkingDirectoryPath).isDirectory()) { >+ fail("BatchCompilerTest#testInference14 current working directory is not a directory " + currentWorkingDirectoryPath); >+ } >+ String lib1Path = currentWorkingDirectoryPath + File.separator + "lib1.jar"; >+ try { >+ Util.createJar( >+ new String[] { >+ "Bundle.java", >+ "public class Bundle {\n" + >+ " static <A> A adapt(Class<A> type) {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}" >+ }, >+ null, >+ lib1Path, >+ JavaCore.VERSION_1_5); >+ this.runNegativeTest( >+ new String[] { >+ "src/X.java", >+ "public class X {\n" + >+ " Bundle b = Bundle.adapt(BundleWiring.class);\n" + >+ "}\n" + >+ "class BundleWiring {}\n", >+ }, >+ "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" >+ + " -cp lib1.jar" // relative >+ + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" >+ + " -1.5 -g -preserveAllLocals" >+ + " -proceedOnError -referenceInfo" >+ + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", >+ "", >+ "----------\n" + >+ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 2)\n" + >+ " Bundle b = Bundle.adapt(BundleWiring.class);\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from BundleWiring to Bundle\n" + >+ "----------\n" + >+ "1 problem (1 error)", >+ true); >+ } catch (IOException e) { >+ System.err.println("BatchCompilerTest#testInference14 could not write to current working directory " + currentWorkingDirectoryPath); >+ } finally { >+ new File(lib1Path).delete(); >+ } >+} > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 328775
:
181779
|
181923
|
181936
| 182019