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 207268 Details for
Bug 363858
[dom] early throwing of AbortCompilation causes NPE in CompilationUnitResolver
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
more fixes
Bug_363858_v2.patch (text/plain), 37.88 KB, created by
Stephan Herrmann
on 2011-11-19 14:50:23 EST
(
hide
)
Description:
more fixes
Filename:
MIME Type:
Creator:
Stephan Herrmann
Created:
2011-11-19 14:50:23 EST
Size:
37.88 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java >index b8fec17..dc197f4 100644 >--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java >+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java >@@ -1530,7 +1530,7 @@ public void test_illegal_annotation_002() { > }, > customOptions, > "----------\n" + >- "1. ERROR in X.java (at line 0)\n" + >+ "1. ERROR in X.java (at line 1)\n" + > " public class X {\n" + > " ^\n" + > "Cannot use the unqualified name \'NichtNull\' as an annotation name for null specification\n" + >diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java >index d3e6b2b..537f730 100644 >--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java >+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -185,6 +185,9 @@ private static Class[] getAllTestClasses() { > UtilTests.class, > > JavaCoreOptionsTests.class, >+ >+ // Tests regarding null-annotations: >+ NullAnnotationModelTests.class, > }; > > Class[] deprecatedClasses = getDeprecatedJDOMTestClasses(); >diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java >new file mode 100644 >index 0000000..da0622a >--- /dev/null >+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java >@@ -0,0 +1,410 @@ >+/******************************************************************************* >+ * Copyright (c) 2011 GK Software AG and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Stephan Herrmann - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.core.tests.model; >+ >+import java.io.File; >+import java.io.IOException; >+import java.io.StringBufferInputStream; >+import java.net.URL; >+import java.util.Hashtable; >+ >+import junit.framework.Test; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IMarker; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IncrementalProjectBuilder; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.FileLocator; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaModelMarker; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.compiler.IProblem; >+import org.eclipse.jdt.core.dom.AST; >+import org.eclipse.jdt.core.dom.ASTParser; >+import org.eclipse.jdt.core.dom.CompilationUnit; >+ >+public class NullAnnotationModelTests extends ReconcilerTests { >+ >+ String ANNOTATION_LIB; >+ >+ public static Test suite() { >+ return buildModelTestSuite(NullAnnotationModelTests.class); >+ } >+ >+ public NullAnnotationModelTests(String name) { >+ super(name); >+ } >+ >+ static { >+// TESTS_NAMES = new String[] { "testMissingAnnotation5" }; >+ } >+ >+ public void setUp() throws Exception { >+ super.setUp(); >+ File bundleFile = FileLocator.getBundleFile(Platform.getBundle("org.eclipse.jdt.annotation.null")); >+ this.ANNOTATION_LIB = bundleFile.isDirectory() ? bundleFile.getPath()+"/bin" : bundleFile.getPath(); >+ } >+ >+ protected String testJarPath(String jarName) throws IOException { >+ URL libEntry = Platform.getBundle("org.eclipse.jdt.core.tests.model").getEntry("/workspace/NullAnnotations/lib/"+jarName); >+ return FileLocator.toFileURL(libEntry).getPath(); >+ } >+ >+ >+ public void testConvertedSourceType1() throws CoreException, InterruptedException { >+ try { >+ // Resources creation >+ IJavaProject p = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB", this.ANNOTATION_LIB}, "bin", "1.5"); >+ p.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); >+ p.setOption(JavaCore.COMPILER_NONNULL_IS_DEFAULT, JavaCore.ENABLED); >+ >+ this.createFolder("/P/p1"); >+ String c1SourceString = >+ "package p1;\n" + >+ "import org.eclipse.jdt.annotation.*;\n" + >+ "public class C1 {\n" + >+ " public String foo(@Nullable Object arg) {\n" + // this is consumed via SourceTypeConverter >+ " return arg == null ? \"\" : arg.toString();\n" + >+ " }\n" + >+ "}\n"; >+ this.createFile( >+ "/P/p1/C1.java", >+ c1SourceString); >+ >+ this.createFolder("/P/p2"); >+ String c2SourceString = >+ "package p2;\n" + >+ "public class C2 {\n" + >+ " String bar(p1.C1 c, C2 c2) {;\n" + >+ " return c.foo(null);\n" + // don't complain despite default nonnull, foo has explicit @Nullable >+ " }\n" + >+ " String foo(Object arg) {\n" + >+ " return arg == null ? null : arg.toString();\n" + >+ " }\n" + >+ "}\n"; >+ this.createFile( >+ "/P/p2/C2.java", >+ c2SourceString); >+ >+ char[] c2SourceChars = c2SourceString.toCharArray(); >+ this.problemRequestor.initialize(c2SourceChars); >+ >+ getCompilationUnit("/P/p2/C2.java").getWorkingCopy(this.wcOwner, null); >+ >+ assertProblems("Unexpected problems", "----------\n" + >+ "1. WARNING in /P/p2/C2.java (at line 7)\n" + >+ " return arg == null ? null : arg.toString();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Potential type mismatch: required \'@NonNull String\' but nullness of the provided value is unknown\n" + >+ "----------\n"); >+ } finally { >+ deleteProject("P"); >+ } >+ } >+ >+ public void testBinaryType1() throws CoreException, InterruptedException, IOException { >+ try { >+ // Resources creation >+ IJavaProject p = createJavaProject("P", new String[] {""}, >+ new String[] {"JCL15_LIB", this.ANNOTATION_LIB, testJarPath("example.jar")}, >+ "bin", "1.5"); >+ p.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); >+ p.setOption(JavaCore.COMPILER_NONNULL_IS_DEFAULT, JavaCore.ENABLED); >+ >+ // example.jar contains p1/C1.java just like testConvertedSourceType1() >+ >+ this.createFolder("/P/p2"); >+ String c2SourceString = >+ "package p2;\n" + >+ "public class C2 {\n" + >+ " String bar(p1.C1 c) {;\n" + >+ " return c.foo(null);\n" + // don't complain despite default nonnull, foo has explicit @Nullable >+ " }\n" + >+ " String foo(Object arg) {\n" + >+ " return arg == null ? null : arg.toString();\n" + >+ " }\n" + >+ "}\n"; >+ this.createFile( >+ "/P/p2/C2.java", >+ c2SourceString); >+ >+ char[] c2SourceChars = c2SourceString.toCharArray(); >+ this.problemRequestor.initialize(c2SourceChars); >+ >+ getCompilationUnit("/P/p2/C2.java").getWorkingCopy(this.wcOwner, null); >+ >+ assertProblems("Unexpected problems", "----------\n" + >+ "1. WARNING in /P/p2/C2.java (at line 7)\n" + >+ " return arg == null ? null : arg.toString();\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Potential type mismatch: required \'@NonNull String\' but nullness of the provided value is unknown\n" + >+ "----------\n"); >+ } finally { >+ deleteProject("P"); >+ } >+ } >+ >+ public void testMissingAnnotation1() throws CoreException { >+ try { >+ // Resources creation >+ IJavaProject p = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB", this.ANNOTATION_LIB}, "bin", "1.5"); >+ p.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); >+ p.setOption(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "in.valid"); >+ >+ this.createFolder("/P/p1"); >+ String c1SourceString = >+ "package p1;\n" + >+ "@org.eclipse.jdt.annotation.NonNullByDefault\n" + >+ "public class C1 {\n" + >+ " public String foo(Object arg) {\n" + >+ " return arg == null ? \"\" : arg.toString();\n" + >+ " }\n" + >+ "}\n"; >+ this.createFile( >+ "/P/p1/C1.java", >+ c1SourceString); >+ >+ this.problemRequestor.initialize(c1SourceString.toCharArray()); >+ >+ getCompilationUnit("/P/p1/C1.java").getWorkingCopy(this.wcOwner, null); >+ >+ assertProblems("Unexpected problems", >+ "----------\n" + >+ "1. ERROR in /P/p1/C1.java (at line 1)\n" + >+ " package p1;\n" + >+ " ^\n" + >+ "Buildpath problem: the type in.valid, which is configured as a null annotation type, cannot be resolved\n" + >+ "----------\n"); >+ } finally { >+ deleteProject("P"); >+ } >+ } >+ >+ public void testMissingAnnotation2() throws CoreException { >+ Hashtable javaOptions = JavaCore.getOptions(); >+ try { >+ // Resources creation >+ IJavaProject p = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB", this.ANNOTATION_LIB}, "bin", "1.5"); >+ IFile settings = (IFile) p.getProject().findMember(".settings/org.eclipse.jdt.core.prefs"); >+ settings.appendContents(new StringBufferInputStream("\norg.eclipse.jdt.core.compiler.annotation.nonnull=not.valid\n"), 0, null); >+ p.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); >+ >+ this.createFolder("/P/p1"); >+ String c1SourceString = >+ "package p1;\n" + >+ "@org.eclipse.jdt.annotation.NonNullByDefault\n" + >+ "public class C1 {\n" + >+ " public String foo(Object arg) {\n" + >+ " return arg == null ? \"\" : arg.toString();\n" + >+ " }\n" + >+ "}\n"; >+ this.createFile( >+ "/P/p1/C1.java", >+ c1SourceString); >+ >+ this.problemRequestor.initialize(c1SourceString.toCharArray()); >+ >+ getCompilationUnit("/P/p1/C1.java").getWorkingCopy(this.wcOwner, null); >+ >+ assertProblems("Unexpected problems", >+ "----------\n" + >+ "1. ERROR in /P/p1/C1.java (at line 1)\n" + >+ " package p1;\n" + >+ " ^\n" + >+ "Buildpath problem: the type not.valid, which is configured as a null annotation type, cannot be resolved\n" + >+ "----------\n"); >+ } finally { >+ deleteProject("P"); >+ JavaCore.setOptions(javaOptions); >+ // work against side-effect of JavaRuntime listening to change of prefs-file. >+ // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=302850#c25 >+ } >+ } >+ >+ // Bug 363858 - [dom] early throwing of AbortCompilation causes NPE in CompilationUnitResolver >+ public void testMissingAnnotation3() throws CoreException { >+ try { >+ // Resources creation >+ IJavaProject p = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB", this.ANNOTATION_LIB}, "bin", "1.5"); >+ p.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); >+ p.setOption(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "invalid"); >+ >+ this.createFolder("/P/p1"); >+ String c1SourceString = >+ "package p1;\n" + >+ "@org.eclipse.jdt.annotation.NonNullByDefault\n" + >+ "public class C1 {\n" + >+ " public String foo(Object arg) {\n" + >+ " return arg == null ? \"\" : arg.toString();\n" + >+ " }\n" + >+ "}\n"; >+ this.createFile( >+ "/P/p1/C1.java", >+ c1SourceString); >+ >+ this.problemRequestor.initialize(c1SourceString.toCharArray()); >+ >+ final ICompilationUnit unit = getCompilationUnit("/P/p1/C1.java").getWorkingCopy(this.wcOwner, null); >+ assertProblems("Unexpected problems", >+ "----------\n" + >+ "1. ERROR in /P/p1/C1.java (at line 0)\n" + >+ " package p1;\n" + >+ " ^\n" + >+ "Cannot use the unqualified name \'invalid\' as an annotation name for null specification\n" + >+ "----------\n"); >+ >+ ASTParser parser = ASTParser.newParser(AST.JLS4); >+ parser.setProject(p); >+ parser.setResolveBindings(true); >+ parser.setSource(unit); >+ CompilationUnit ast = (CompilationUnit) parser.createAST(null); >+ assertNotNull("ast should not be null", ast); >+ this.problemRequestor.reset(); >+ this.problemRequestor.beginReporting(); >+ IProblem[] problems = ast.getProblems(); >+ for (int i=0; i<problems.length; i++) >+ this.problemRequestor.acceptProblem(problems[i]); >+ assertProblems("Unexpected problems (2)", >+ "----------\n" + >+ "1. ERROR in /P/p1/C1.java (at line 0)\n" + >+ " package p1;\n" + >+ " ^\n" + >+ "Cannot use the unqualified name \'invalid\' as an annotation name for null specification\n" + >+ "----------\n"); >+ } finally { >+ deleteProject("P"); >+ } >+ } >+ >+ // initialization of null annotations is triggered from package-info.java: illegal simple name >+ public void testMissingAnnotation4() throws CoreException { >+ try { >+ // Resources creation >+ IJavaProject p = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB", this.ANNOTATION_LIB}, "bin", "1.5"); >+ p.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); >+ p.setOption(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "invalid"); >+ >+ this.createFolder("/P/p1"); >+ String piSourceString = >+ "@org.eclipse.jdt.annotation.NonNullByDefault\n" + >+ "package p1;\n"; >+ this.createFile( >+ "/P/p1/package-info.java", >+ piSourceString); >+ >+ this.problemRequestor.initialize(piSourceString.toCharArray()); >+ >+ // Challenge CompilationUnitProblemFinder: >+ final ICompilationUnit unit = getCompilationUnit("/P/p1/package-info.java").getWorkingCopy(this.wcOwner, null); >+ String expectedError = "----------\n" + >+ "1. ERROR in /P/p1/package-info.java (at line 0)\n" + >+ " @org.eclipse.jdt.annotation.NonNullByDefault\n" + >+ " ^\n" + >+ "Cannot use the unqualified name \'invalid\' as an annotation name for null specification\n" + >+ "----------\n"; >+ assertProblems("Unexpected problems from CompilationUnitProblemFinder", expectedError); >+ >+ // Challenge JavaBuilder: >+ p.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); >+ IMarker[] markers = p.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE); >+ assertMarkers("Unexpected markers", >+ "Cannot use the unqualified name 'invalid' as an annotation name for null specification", >+ markers); >+ assertEquals("Unexpected marker path", "/P", markers[0].getResource().getFullPath().toString()); >+ >+ // Challenge CompilationUnitResolver: >+ ASTParser parser = ASTParser.newParser(AST.JLS4); >+ parser.setProject(p); >+ parser.setResolveBindings(true); >+ parser.setSource(unit); >+ CompilationUnit ast = (CompilationUnit) parser.createAST(null); >+ assertNotNull("ast should not be null", ast); >+ this.problemRequestor.reset(); >+ this.problemRequestor.beginReporting(); >+ IProblem[] problems = ast.getProblems(); >+ for (int i=0; i<problems.length; i++) >+ this.problemRequestor.acceptProblem(problems[i]); >+ assertProblems("Unexpected problems from CompilationUnitResolver", expectedError); >+ } finally { >+ deleteProject("P"); >+ } >+ } >+ >+ // initialization of null annotations is >+ // - triggered from resolveTypesFor(MethodBinding) >+ // - default is defined in package-info.java: >+ // must detect missing non-null annotation and report against the project >+ public void testMissingAnnotation5() throws CoreException, InterruptedException { >+ try { >+ // Resources creation >+ IJavaProject p = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB", this.ANNOTATION_LIB}, "bin", "1.5"); >+ p.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); >+ p.setOption(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "pack.Missing"); >+ >+ this.createFolder("/P/p1"); >+ String piSourceString = >+ "@org.eclipse.jdt.annotation.NonNullByDefault\n" + >+ "package p1;\n"; >+ this.createFile("/P/p1/package-info.java", piSourceString); >+ >+ String c1SourceString = >+ "package p1;\n" + >+ "public class C1 {\n" + >+ " String foo(String arg) { return arg; }\n" + >+ "}\n"; >+ this.createFile("/P/p1/C1.java", c1SourceString); >+ >+ this.problemRequestor.initialize(piSourceString.toCharArray()); >+ >+ // Challenge CompilationUnitProblemFinder: >+ assertNoProblem(piSourceString.toCharArray(), getCompilationUnit("/P/p1/package-info.java")); >+ >+ this.problemRequestor.initialize(c1SourceString.toCharArray()); >+ >+ // Challenge CompilationUnitProblemFinder: >+ ICompilationUnit unit = getCompilationUnit("/P/p1/C1.java").getWorkingCopy(this.wcOwner, null); >+ String expectedError = "----------\n" + >+ "1. ERROR in /P/p1/C1.java (at line 1)\n" + >+ " package p1;\n" + >+ " ^\n" + >+ "Buildpath problem: the type pack.Missing, which is configured as a null annotation type, cannot be resolved\n" + >+ "----------\n"; >+ assertProblems("Unexpected problems", expectedError); >+ >+ // Challenge JavaBuilder: >+ p.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); >+ IMarker[] markers = p.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE); >+ assertMarkers("Unexpected markers", >+ "Buildpath problem: the type pack.Missing, which is configured as a null annotation type, cannot be resolved", >+ markers); >+ assertEquals("Unexpected marker path", "/P", markers[0].getResource().getFullPath().toString()); >+ >+ // Challenge CompilationUnitResolver: >+ ASTParser parser = ASTParser.newParser(AST.JLS4); >+ parser.setProject(p); >+ parser.setResolveBindings(true); >+ parser.setSource(unit); >+ CompilationUnit ast = (CompilationUnit) parser.createAST(null); >+ assertNotNull("ast should not be null", ast); >+ this.problemRequestor.reset(); >+ this.problemRequestor.beginReporting(); >+ IProblem[] problems = ast.getProblems(); >+ for (int i=0; i<problems.length; i++) >+ this.problemRequestor.acceptProblem(problems[i]); >+ assertProblems("Unexpected problems (2)", expectedError); >+ } finally { >+ deleteProject("P"); >+ } >+ } >+} >diff --git a/org.eclipse.jdt.core.tests.model/workspace/NullAnnotations/lib/example.jar b/org.eclipse.jdt.core.tests.model/workspace/NullAnnotations/lib/example.jar >new file mode 100644 >index 0000000..4f9b0ca >Binary files /dev/null and b/org.eclipse.jdt.core.tests.model/workspace/NullAnnotations/lib/example.jar differ >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java >index 44a69a0..03452cd 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java >@@ -695,6 +695,7 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { > > // Switch the current policy and compilation result for this unit to the requested one. > for (int i = 0; i < maxUnits; i++) { >+ CompilationResult unitResult = null; > try { > if (this.options.verbose) { > this.out.println( >@@ -707,8 +708,7 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { > } > // diet parsing for large collection of units > CompilationUnitDeclaration parsedUnit; >- CompilationResult unitResult = >- new CompilationResult(sourceUnits[i], i, maxUnits, this.options.maxProblemsPerUnit); >+ unitResult = new CompilationResult(sourceUnits[i], i, maxUnits, this.options.maxProblemsPerUnit); > long parseStart = System.currentTimeMillis(); > if (this.totalUnits < this.parseThreshold) { > parsedUnit = this.parser.parse(sourceUnits[i], unitResult); >@@ -727,6 +727,11 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { > } > //} catch (AbortCompilationUnit e) { > // requestor.acceptResult(unitResult.tagAsAccepted()); >+ } catch (AbortCompilation a) { >+ // best effort to find a way for reporting this problem: >+ if (a.compilationResult == null) >+ a.compilationResult = unitResult; >+ throw a; > } finally { > sourceUnits[i] = null; // no longer hold onto the unit > } >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java >index 5d93d65..710011a 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java >@@ -78,7 +78,8 @@ public class LookupEnvironment implements ProblemReasons, TypeConstants { > public boolean isProcessingAnnotations = false; > public boolean mayTolerateMissingType = false; > >- boolean nullAnnotationsInitialized = false; >+ private char[][][] nullAnnotationPackageNames = null; // package parts of globalOptions.{nullableAnnotationName,nonNullAnnotationName,nonNullByDefaultAnnotationName} >+ private char[][] nullAnnotationSimpleNames = null; // type parts of globalOptions.{nullableAnnotationName,nonNullAnnotationName,nonNullByDefaultAnnotationName} > > final static int BUILD_FIELDS_AND_METHODS = 4; > final static int BUILD_TYPE_HIERARCHY = 1; >@@ -728,8 +729,6 @@ public MissingTypeBinding createMissingType(PackageBinding packageBinding, char[ > * 3. Create the method bindings > */ > public PackageBinding createPackage(char[][] compoundName) { >- if (!this.nullAnnotationsInitialized) >- initNullAnnotationPackages(); > PackageBinding packageBinding = getPackage0(compoundName[0]); > if (packageBinding == null || packageBinding == TheNotFoundPackage) { > packageBinding = new PackageBinding(compoundName[0], this); >@@ -1128,6 +1127,56 @@ public TypeBinding getNullAnnotationBindingFromDefault(long defaultTagBit, boole > return null; > } > >+/** answer the simple names of annotation types nullable/nonnull/nonnullbydefault if their package is packageName. */ >+char[][] getNullAnnotationNames(char[][] packageName) { >+ if (this.nullAnnotationPackageNames == null) { >+ // fetch and split names from globalOptions to local fields nullAnnotationPackageNames & nullAnnotationsSimpleNames: >+ this.nullAnnotationPackageNames = new char[3][][]; >+ this.nullAnnotationSimpleNames = new char[3][]; >+ char[][][] compoundNames = new char[][][] {getNullableAnnotationName(), getNonNullAnnotationName(), getNonNullByDefaultAnnotationName() }; >+ for (int i=0; i<3; i++) { >+ int len = compoundNames[i].length; >+ if (len < 2) { >+ this.problemReporter.nullAnnotationNameMustBeQualified(compoundNames[i], this.unitBeingCompleted); >+ // the above error may or may not throw AbortCompilation (is problemReporter.referenceContext set?) >+ continue; >+ } >+ this.nullAnnotationPackageNames[i] = CharOperation.subarray(compoundNames[i], 0, len-1); >+ this.nullAnnotationSimpleNames[i] = compoundNames[i][len-1]; >+ } >+ } >+ // search in local storage: >+ boolean found = false; >+ char[][] simpleNames = new char[3][]; >+ for (int i=0; i<3; i++) { >+ if (CharOperation.equals(packageName, this.nullAnnotationPackageNames[i])) { >+ simpleNames[i] = this.nullAnnotationSimpleNames[i]; >+ found = true; >+ } >+ } >+ if (found) >+ return simpleNames; >+ else >+ return null; >+} >+ >+TypeBinding getNullAnnotationResolved(TypeBinding nullAnnotation, Scope scope) { >+ // avoid unspecific error "The type in.valid cannot be resolved. It is indirectly referenced from required .class files" >+ boolean tolerateMissing = this.mayTolerateMissingType; >+ this.mayTolerateMissingType = true; >+ try { >+ nullAnnotation = BinaryTypeBinding.resolveType(nullAnnotation, this, false); >+ } finally { >+ this.mayTolerateMissingType = tolerateMissing; >+ } >+ if (nullAnnotation instanceof MissingTypeBinding) { >+ // convert error into a specific one: >+ scope.problemReporter().missingNullAnnotationType(((MissingTypeBinding)nullAnnotation).compoundName); >+ return null; >+ } >+ return nullAnnotation; >+} >+ > /* Answer the top level package named name if it exists in the cache. > * Answer theNotFoundPackage if it could not be resolved the first time > * it was looked up, otherwise answer null. >@@ -1161,8 +1210,6 @@ public ReferenceBinding getResolvedType(char[][] compoundName, Scope scope) { > * Answer null if the package cannot be found. > */ > PackageBinding getTopLevelPackage(char[] name) { >- if (!this.nullAnnotationsInitialized) >- initNullAnnotationPackages(); > PackageBinding packageBinding = getPackage0(name); > if (packageBinding != null) { > if (packageBinding == TheNotFoundPackage) >@@ -1444,41 +1491,6 @@ TypeBinding getTypeFromVariantTypeSignature( > } > } > >-private void initNullAnnotationPackages() { >- this.nullAnnotationsInitialized = true; >- if (!this.globalOptions.isAnnotationBasedNullAnalysisEnabled) >- return; >- char[][] compoundName = getNullableAnnotationName(); >- if (compoundName != null) >- initNullAnnotationPackage(compoundName, TypeIds.T_ConfiguredAnnotationNullable); >- compoundName = getNonNullAnnotationName(); >- if (compoundName != null) >- initNullAnnotationPackage(compoundName, TypeIds.T_ConfiguredAnnotationNonNull); >- compoundName = getNonNullByDefaultAnnotationName(); >- if (compoundName != null) >- initNullAnnotationPackage(compoundName, TypeIds.T_ConfiguredAnnotationNonNullByDefault); >-} >- >-/** >- * Create or retrieve the package holding the specified type and store the type name. >- */ >-void initNullAnnotationPackage(char[][] typeName, int typeId) { >- if (typeName.length < 2) { >- this.problemReporter.nullAnnotationNameMustBeQualified(typeName); >- return; >- } >- char[][] packageName = CharOperation.subarray(typeName, 0, typeName.length-1); >- PackageBinding packageBinding = createPackage(packageName); >- char[] simpleTypeName = typeName[typeName.length-1]; >- if (typeId == TypeIds.T_ConfiguredAnnotationNullable) >- packageBinding.nullableName = simpleTypeName; >- else if (typeId == TypeIds.T_ConfiguredAnnotationNonNull) >- packageBinding.nonNullName = simpleTypeName; >- else if (typeId == TypeIds.T_ConfiguredAnnotationNonNullByDefault) >- packageBinding.nonNullByDefaultName = simpleTypeName; >-} >- >- > boolean isMissingType(char[] typeName) { > for (int i = this.missingTypes == null ? 0 : this.missingTypes.size(); --i >= 0;) { > MissingTypeBinding missingType = (MissingTypeBinding) this.missingTypes.get(i); >@@ -1546,8 +1558,6 @@ public void reset() { > this.unitBeingCompleted = null; // in case AbortException occurred > > this.classFilePool.reset(); >- >- this.nullAnnotationsInitialized = false; > > // name environment has a longer life cycle, and must be reset in > // the code which created it. >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java >index 54a5397..bc6862b 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java >@@ -24,9 +24,11 @@ public class PackageBinding extends Binding implements TypeConstants { > HashtableOfType knownTypes; > HashtableOfPackage knownPackages; > >+ // if this package contains configured null-annotations, store their simple names here: > protected char[] nullableName = null; > protected char[] nonNullName = null; > protected char[] nonNullByDefaultName = null; >+ // annotation type binding representing the default that has been defined for this package (using @NonNullByDefault) > protected TypeBinding nullnessDefaultAnnotation; > > protected PackageBinding() { >@@ -43,6 +45,8 @@ public PackageBinding(char[][] compoundName, PackageBinding parent, LookupEnviro > this.environment = environment; > this.knownTypes = null; // initialized if used... class counts can be very large 300-600 > this.knownPackages = new HashtableOfPackage(3); // sub-package counts are typically 0-3 >+ if (compoundName != CharOperation.NO_CHAR_CHAR && environment.globalOptions.isAnnotationBasedNullAnalysisEnabled) >+ initNullAnnotationPackage(); > } > > public PackageBinding(LookupEnvironment environment) { >@@ -213,6 +217,19 @@ public Binding getTypeOrPackage(char[] name) { > > return null; > } >+ >+private void initNullAnnotationPackage() { >+ char[][] simpleAnnotNames = this.environment.getNullAnnotationNames(this.compoundName); >+ if (simpleAnnotNames == null) >+ return; >+ if (simpleAnnotNames[0] != null) >+ this.nullableName = simpleAnnotNames[0]; >+ if (simpleAnnotNames[1] != null) >+ this.nonNullName = simpleAnnotNames[1]; >+ if (simpleAnnotNames[2] != null) >+ this.nonNullByDefaultName = simpleAnnotNames[2]; >+} >+ > public final boolean isViewedAsDeprecated() { > if ((this.tagBits & TagBits.DeprecatedAnnotationResolved) == 0) { > this.tagBits |= TagBits.DeprecatedAnnotationResolved; >@@ -253,9 +270,9 @@ void setupNullAnnotationType(ReferenceBinding type) { > type.id = id; // ensure annotations of this type are detected as standard annotations. > } > >-public TypeBinding getNullnessDefaultAnnotation() { >+public TypeBinding getNullnessDefaultAnnotation(Scope scope) { > if (this.nullnessDefaultAnnotation instanceof UnresolvedReferenceBinding) >- return this.nullnessDefaultAnnotation = BinaryTypeBinding.resolveType(this.nullnessDefaultAnnotation, this.environment, false); >+ return this.nullnessDefaultAnnotation = this.environment.getNullAnnotationResolved(this.nullnessDefaultAnnotation, scope); > return this.nullnessDefaultAnnotation; > } > >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java >index 94abc4f..07ef1da 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java >@@ -1640,8 +1640,7 @@ private void evaluateNullAnnotations(long annotationTagBits) { > } > private TypeBinding getNullnessDefaultAnnotation() { > if (this.nullnessDefaultAnnotation instanceof UnresolvedReferenceBinding) >- return this.nullnessDefaultAnnotation = >- BinaryTypeBinding.resolveType(this.nullnessDefaultAnnotation, getPackage().environment, false); >+ this.nullnessDefaultAnnotation = this.scope.environment().getNullAnnotationResolved(this.nullnessDefaultAnnotation, this.scope); > return this.nullnessDefaultAnnotation; > } > /** >@@ -1671,13 +1670,14 @@ private TypeBinding findDefaultNullness(MethodBinding methodBinding, LookupEnvir > } > > // package >- annotationBinding = type.getPackage().getNullnessDefaultAnnotation(); >+ annotationBinding = type.getPackage().getNullnessDefaultAnnotation(this.scope); > if (annotationBinding != null) > return annotationBinding; > > // global > long defaultNullness = environment.globalOptions.defaultNonNullness; > if (defaultNullness != 0) { >+ // we have a default, so we need an annotation type to record this during compile and in the byte code > annotationBinding = environment.getNullAnnotationBinding(defaultNullness, true/*resolve*/); > if (annotationBinding != null) > return annotationBinding; >@@ -1685,8 +1685,6 @@ private TypeBinding findDefaultNullness(MethodBinding methodBinding, LookupEnvir > // on this branch default was not defined using an annotation, thus annotation type can still be missing > if (defaultNullness == TagBits.AnnotationNonNull) > this.scope.problemReporter().missingNullAnnotationType(environment.getNonNullAnnotationName()); >- else if (defaultNullness == TagBits.AnnotationNullable) >- this.scope.problemReporter().missingNullAnnotationType(environment.getNullableAnnotationName()); > else > this.scope.problemReporter().abortDueToInternalError("Illegal default nullness value: "+defaultNullness); //$NON-NLS-1$ > // reset default to avoid duplicate errors: >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java >index baeb26c..4c1e8a7 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java >@@ -8191,7 +8191,8 @@ public void cannotImplementIncompatibleNullness(MethodBinding currentMethod, Met > sourceEnd); > } > >-public void nullAnnotationNameMustBeQualified(char[][] typeName) { >+public void nullAnnotationNameMustBeQualified(char[][] typeName, CompilationUnitDeclaration unitBeingCompleted) { >+ this.referenceContext = unitBeingCompleted; > String[] name = {new String(typeName[0])}; > this.handle(IProblem.NullAnnotationNameMustBeQualified, name, name, 0, 0); > } >diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java >index 0fdbd0a..0bd8162 100644 >--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java >+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java >@@ -99,6 +99,7 @@ class CompilationUnitResolver extends Compiler { > DefaultBindingResolver.BindingTables bindingTables; > > boolean hasCompilationAborted; >+ CategorizedProblem abortProblem; > > private IProgressMonitor monitor; > >@@ -364,6 +365,7 @@ class CompilationUnitResolver extends Compiler { > removeUnresolvedBindings(unit); > } > this.hasCompilationAborted = true; >+ this.abortProblem = abortException.problem; > } > > public static void parse(ICompilationUnit[] compilationUnits, ASTRequestor astRequestor, int apiLevel, Map options, int flags, IProgressMonitor monitor) { >@@ -689,11 +691,16 @@ class CompilationUnitResolver extends Compiler { > // the bindings could not be resolved due to missing types in name environment > // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=86541 > CompilationUnitDeclaration unitDeclaration = parse(sourceUnit, nodeSearcher, options, flags); >- final int problemCount = unit.compilationResult.problemCount; >- if (problemCount != 0) { >- unitDeclaration.compilationResult.problems = new CategorizedProblem[problemCount]; >- System.arraycopy(unit.compilationResult.problems, 0, unitDeclaration.compilationResult.problems, 0, problemCount); >- unitDeclaration.compilationResult.problemCount = problemCount; >+ if (unit != null) { >+ final int problemCount = unit.compilationResult.problemCount; >+ if (problemCount != 0) { >+ unitDeclaration.compilationResult.problems = new CategorizedProblem[problemCount]; >+ System.arraycopy(unit.compilationResult.problems, 0, unitDeclaration.compilationResult.problems, 0, problemCount); >+ unitDeclaration.compilationResult.problemCount = problemCount; >+ } >+ } else if (resolver.abortProblem != null) { >+ unitDeclaration.compilationResult.problemCount = 1; >+ unitDeclaration.compilationResult.problems = new CategorizedProblem[] { resolver.abortProblem }; > } > return unitDeclaration; > } >diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ReconcileWorkingCopyOperation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ReconcileWorkingCopyOperation.java >index 8095a3d..04baf0e 100644 >--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ReconcileWorkingCopyOperation.java >+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ReconcileWorkingCopyOperation.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -132,6 +132,8 @@ public class ReconcileWorkingCopyOperation extends JavaModelOperation { > if (categorizedProblems == null) continue; > for (int i = 0, length = categorizedProblems.length; i < length; i++) { > CategorizedProblem problem = categorizedProblems[i]; >+ if (problem.getCategoryID() == CategorizedProblem.CAT_BUILDPATH) >+ continue; // don't report these problems against any CU, are already reported against the project > if (JavaModelManager.VERBOSE){ > System.out.println("PROBLEM FOUND while reconciling : " + problem.getMessage());//$NON-NLS-1$ > } >diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java >index 531b2b5..99e2651 100644 >--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java >+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -700,6 +700,9 @@ protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] prob > ); > // even if we're not keeping more markers, still fall through rest of the problem reporting, so that offending > // IsClassPathCorrect problem gets recorded since it may help locate the offending reference >+ } else if (problem.getCategoryID() == CategorizedProblem.CAT_BUILDPATH) { >+ // also report other build-path problems against the project, but using a normal problem marker >+ resource = this.javaBuilder.currentProject; > } > > String markerType = problem.getMarkerType();
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 363858
:
207043
|
207044
| 207268