Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2020-11-16 10:49:46 +0000
committerJay Arthanareeswaran2020-11-16 10:49:46 +0000
commit2882dea2c2dbeae235579eb8d1bf3e4d599b879b (patch)
treeb28761c5f3d54b0023570965b665e7f0688fa85d
parent5c287a0cdd528acaed0af3f16707b1be6d9232b0 (diff)
downloadeclipse.jdt.core-2882dea2c2dbeae235579eb8d1bf3e4d599b879b.tar.gz
eclipse.jdt.core-2882dea2c2dbeae235579eb8d1bf3e4d599b879b.tar.xz
eclipse.jdt.core-2882dea2c2dbeae235579eb8d1bf3e4d599b879b.zip
Bug 561544 - NullPointerException in Expression.forcedToBeRaw when
COMPILER_PB_UNAVOIDABLE_GENERIC_TYPE_PROBLEMS is disabled Change-Id: If4e391f6dee7636cda1d1272dace56c622a0e676 Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java45
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java5
2 files changed, 48 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
index d5ce778598..f71d4bdd4b 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -6614,5 +6614,48 @@ public void testBug552388b() {
},
output);
}
+public void testBug561544() {
+ if (this.complianceLevel < ClassFileConstants.JDK11)
+ return;
+ Map customOptions = getCompilerOptions();
+ customOptions.put(JavaCore.COMPILER_PB_UNAVOIDABLE_GENERIC_TYPE_PROBLEMS, JavaCore.DISABLED);
+ runNegativeTest(false,
+ new String[] {
+ "com/bsbportal/music/C2193c.java",
+ "package com.bsbportal.music;\n"
+ + "\n"
+ + "public class C2193c {\n"
+ + " java.util.List f6088b;\n"
+ + " public void onResponse(p594x.C14183r<java.lang.String> rVar) {\n"
+ + " mo12821b((java.util.List<java.lang.String>) this.f6088b);\n"
+ + " }\n"
+ + "}\n"
+ },
+ null,
+ customOptions,
+ "----------\n" +
+ "1. WARNING in com\\bsbportal\\music\\C2193c.java (at line 4)\n" +
+ " java.util.List f6088b;\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "List is a raw type. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "2. ERROR in com\\bsbportal\\music\\C2193c.java (at line 5)\n" +
+ " public void onResponse(p594x.C14183r<java.lang.String> rVar) {\n" +
+ " ^^^^^\n" +
+ "p594x cannot be resolved to a type\n" +
+ "----------\n" +
+ "3. ERROR in com\\bsbportal\\music\\C2193c.java (at line 6)\n" +
+ " mo12821b((java.util.List<java.lang.String>) this.f6088b);\n" +
+ " ^^^^^^^^\n" +
+ "The method mo12821b(List<String>) is undefined for the type C2193c\n" +
+ "----------\n" +
+ "4. WARNING in com\\bsbportal\\music\\C2193c.java (at line 6)\n" +
+ " mo12821b((java.util.List<java.lang.String>) this.f6088b);\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Type safety: Unchecked cast from List to List<String>\n" +
+ "----------\n",
+ "", "", null
+ );
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java
index 64971275ee..db10305186 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java
@@ -1206,7 +1206,10 @@ public boolean forcedToBeRaw(ReferenceContext referenceContext) {
if (field.type.isRawType()) {
if (referenceContext instanceof AbstractMethodDeclaration) {
AbstractMethodDeclaration methodDecl = (AbstractMethodDeclaration) referenceContext;
- if (TypeBinding.notEquals(field.declaringClass, methodDecl.binding.declaringClass)) { // inherited raw field, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962
+ ReferenceBinding declaringClass = methodDecl.binding != null
+ ? methodDecl.binding.declaringClass
+ : methodDecl.scope.enclosingReceiverType();
+ if (TypeBinding.notEquals(field.declaringClass, declaringClass)) { // inherited raw field, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962
return true;
}
} else if (referenceContext instanceof TypeDeclaration) {

Back to the top