Fixed bug 379630: Regression: NPE during reconcile/build
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java
index 00e1784..807c5ac 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java
@@ -7949,4 +7949,31 @@
compilerOptions /* custom options */
);
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=379530
+public void test379530() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5)
+ return;
+ Map compilerOptions = getCompilerOptions();
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
+ compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE);
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X<S> {\n" +
+ " S s;\n" +
+ " {\n" +
+ " S /*[*/s/*]*/;\n" +
+ " s= X.this.s;" +
+ " }\n" +
+ "}"
+ },
+ "",
+ null /* no extra class libraries */,
+ true /* flush output directory */,
+ null,
+ compilerOptions /* custom options */,
+ null
+ );
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java
index d7824c2..48723a6 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java
@@ -53,12 +53,13 @@
// initialization scope
methodScope = methodScope.enclosingMethodScope();
}
- AbstractMethodDeclaration methodDeclaration = methodScope.referenceMethod();
+ AbstractMethodDeclaration methodDeclaration = (methodScope != null) ? methodScope.referenceMethod() : null;
if (methodDeclaration != null && methodDeclaration.binding != null) {
TypeVariableBinding[] typeVariables = methodDeclaration.binding.typeVariables();
+ if (typeVariables == null) typeVariables = Binding.NO_TYPE_VARIABLES;
if (typeVariables == Binding.NO_TYPE_VARIABLES) {
// Method declares no type variables.
- if (typeVariableBinding.declaringElement instanceof TypeBinding)
+ if (typeVariableBinding != null && typeVariableBinding.declaringElement instanceof TypeBinding)
currentScope.resetDeclaringClassMethodStaticFlag((TypeBinding) typeVariableBinding.declaringElement);
else
currentScope.resetEnclosingMethodStaticFlag();
@@ -73,7 +74,7 @@
}
if (!usesEnclosingTypeVar) {
// uses a type variable not declared by enclosing method
- if (typeVariableBinding.declaringElement instanceof TypeBinding)
+ if (typeVariableBinding != null && typeVariableBinding.declaringElement instanceof TypeBinding)
currentScope.resetDeclaringClassMethodStaticFlag((TypeBinding) typeVariableBinding.declaringElement);
else
currentScope.resetEnclosingMethodStaticFlag();
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
index a89b0be..e593ad0 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
@@ -65,10 +65,14 @@
if (this.enclosingInstance != null) {
flowInfo = this.enclosingInstance.analyseCode(currentScope, flowContext, flowInfo);
} else {
- if (this.binding.declaringClass.superclass().isMemberType() && !this.binding.declaringClass.superclass().isStatic()) {
- // creating an anonymous type of a non-static member type without an enclosing instance of parent type
- currentScope.resetDeclaringClassMethodStaticFlag(this.binding.declaringClass.superclass().enclosingType());
+ if (this.binding != null && this.binding.declaringClass != null) {
+ ReferenceBinding superclass = this.binding.declaringClass.superclass();
+ if (superclass != null && superclass.isMemberType() && !superclass.isStatic()) {
+ // creating an anonymous type of a non-static member type without an enclosing instance of parent type
+ currentScope.resetDeclaringClassMethodStaticFlag(superclass.enclosingType());
+ }
}
+
}
// check captured variables are initialized in current context (26134)
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
index 3dee6e2..4388ebe 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
@@ -995,11 +995,13 @@
ClassScope enclosingClassScope = methodScope.enclosingClassScope();
if (enclosingClassScope != null) {
TypeDeclaration type = enclosingClassScope.referenceContext;
- if (type.binding != null && declaringClass != null && type.binding != declaringClass.original()) {
+ if (type != null && type.binding != null && declaringClass != null && type.binding != declaringClass.original()) {
methodScope = enclosingClassScope.enclosingMethodScope();
} else {
break;
}
+ } else {
+ break;
}
}
}