55102
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java
index 284bacf..35ce10d 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java
@@ -4287,6 +4287,63 @@
sourceUnit.discardWorkingCopy();
}
}
+ /*
+ * Ensures that bindings are created during reconcile if force problem detection is turned on.
+ * Case of a unit containing an anonymous type.
+ * (regression test for bug 55102 NPE when using ICU.reconcile(GET_AST_TRUE, ...))
+ */
+ public void test0538f() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ ReconcilerTests.ProblemRequestor pbRequestor = new ReconcilerTests.ProblemRequestor();
+ sourceUnit.becomeWorkingCopy(pbRequestor, null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " void foo() {\n" +
+ " new Object() {\n" +
+ " void bar() {\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ "}"
+ );
+ CompilationUnit unit = sourceUnit.reconcile(true, true/*force pb detection*/, null, null);
+ ASTNode node = getASTNode(unit, 0);
+ assertNotNull("No node", node);
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /*
+ * Ensures that bindings are created during reconcile if force problem detection is turned on.
+ * Case of a unit containing an anonymous type.
+ * (regression test for bug 55102 NPE when using ICU.reconcile(GET_AST_TRUE, ...))
+ */
+ public void test0538g() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ ReconcilerTests.ProblemRequestor pbRequestor = new ReconcilerTests.ProblemRequestor();
+ sourceUnit.becomeWorkingCopy(pbRequestor, null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " void foo() {\n" +
+ " new Object() {\n" +
+ " void bar() {\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ "}"
+ );
+ sourceUnit.reconcile(false/*don't create AST*/, false/* don't force pb detection*/, null, null);
+ CompilationUnit unit = sourceUnit.reconcile(true/*create AST*/, true/*force pb detection*/, null, null);
+ ASTNode node = getASTNode(unit, 0);
+ assertNotNull("No node", node);
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
/**
* http://dev.eclipse.org/bugs/show_bug.cgi?id=53477
*/
diff --git a/org.eclipse.jdt.core/buildnotes_jdt-core.html b/org.eclipse.jdt.core/buildnotes_jdt-core.html
index 12c2885..5cac753 100644
--- a/org.eclipse.jdt.core/buildnotes_jdt-core.html
+++ b/org.eclipse.jdt.core/buildnotes_jdt-core.html
@@ -46,7 +46,9 @@
</ul>
<h3>Problem Reports Fixed</h3>
-<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=49986">49986</a>
+<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=55102">55102</a>
+NPE when using ICU.reconcile(GET_AST_TRUE, ...)
+<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=49986">49986</a>
setRawClasspath(...) should fire a F_CLASSPATH_CHANGED delta
<a name="v_413"></a>
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java
index d62f72e..a1f65ec 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java
@@ -137,15 +137,22 @@
unitInfo.timestamp = ((IFile)underlyingResource).getModificationStamp();
// compute other problems if needed
- if (computeProblems){
- perWorkingCopyInfo.beginReporting();
- CompilationUnitProblemFinder.process(unit, this, parser, this.owner, perWorkingCopyInfo, problemFactory, pm);
- perWorkingCopyInfo.endReporting();
- }
-
- if (info instanceof ASTHolderCUInfo) {
- org.eclipse.jdt.core.dom.CompilationUnit cu = AST.convertCompilationUnit(unit, contents, options, pm);
- ((ASTHolderCUInfo) info).ast = cu;
+ CompilationUnitDeclaration compilationUnitDeclaration = null;
+ try {
+ if (computeProblems){
+ perWorkingCopyInfo.beginReporting();
+ compilationUnitDeclaration = CompilationUnitProblemFinder.process(unit, this, parser, this.owner, perWorkingCopyInfo, problemFactory, false/*don't cleanup cu*/, pm);
+ perWorkingCopyInfo.endReporting();
+ }
+
+ if (info instanceof ASTHolderCUInfo) {
+ org.eclipse.jdt.core.dom.CompilationUnit cu = AST.convertCompilationUnit(unit, contents, options, pm);
+ ((ASTHolderCUInfo) info).ast = cu;
+ }
+ } finally {
+ if (compilationUnitDeclaration != null) {
+ compilationUnitDeclaration.cleanUp();
+ }
}
return unitInfo.isStructureKnown();
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java
index 249fc77..dff91ba 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java
@@ -135,6 +135,7 @@
WorkingCopyOwner workingCopyOwner,
IProblemRequestor problemRequestor,
IProblemFactory problemFactory,
+ boolean cleanupCU,
IProgressMonitor monitor)
throws JavaModelException {
@@ -185,7 +186,7 @@
Util.log(e, "Exception occurred during problem detection: "); //$NON-NLS-1$
throw new JavaModelException(e, IJavaModelStatusConstants.COMPILER_FAILURE);
} finally {
- if (unit != null) {
+ if (cleanupCU && unit != null) {
unit.cleanUp();
}
problemFinder.lookupEnvironment.reset();
@@ -196,10 +197,11 @@
ICompilationUnit unitElement,
WorkingCopyOwner workingCopyOwner,
IProblemRequestor problemRequestor,
+ boolean cleanupCU,
IProgressMonitor monitor)
throws JavaModelException {
- return process(null/*no CompilationUnitDeclaration*/, unitElement, null/*use default Parser*/, workingCopyOwner, problemRequestor, new DefaultProblemFactory(), monitor);
+ return process(null/*no CompilationUnitDeclaration*/, unitElement, null/*use default Parser*/, workingCopyOwner, problemRequestor, new DefaultProblemFactory(), cleanupCU, monitor);
}
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 1874b66..2a0d5da 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
@@ -66,17 +66,24 @@
// force problem detection? - if structure was consistent
if (forceProblemDetection) {
IProblemRequestor problemRequestor = workingCopy.getPerWorkingCopyInfo();
- if (problemRequestor != null && problemRequestor.isActive()){
- problemRequestor.beginReporting();
- CompilationUnitDeclaration unit = CompilationUnitProblemFinder.process(workingCopy, this.workingCopyOwner, problemRequestor, this.progressMonitor);
- problemRequestor.endReporting();
- if (progressMonitor != null) progressMonitor.worked(1);
- if (this.createAST && unit != null) {
- char[] contents = workingCopy.getContents();
- Map options = workingCopy.getJavaProject().getOptions(true);
- this.ast = AST.convertCompilationUnit(unit, contents, options, this.progressMonitor);
+ if (problemRequestor != null && problemRequestor.isActive()) {
+ CompilationUnitDeclaration unit = null;
+ try {
+ problemRequestor.beginReporting();
+ unit = CompilationUnitProblemFinder.process(workingCopy, this.workingCopyOwner, problemRequestor, false/*don't cleanup cu*/, this.progressMonitor);
+ problemRequestor.endReporting();
if (progressMonitor != null) progressMonitor.worked(1);
- }
+ if (this.createAST && unit != null) {
+ char[] contents = workingCopy.getContents();
+ Map options = workingCopy.getJavaProject().getOptions(true);
+ this.ast = AST.convertCompilationUnit(unit, contents, options, this.progressMonitor);
+ if (progressMonitor != null) progressMonitor.worked(1);
+ }
+ } finally {
+ if (unit != null) {
+ unit.cleanUp();
+ }
+ }
}
}
}