diff options
| author | Sasikanth Bharadwaj | 2017-11-29 08:43:34 +0000 |
|---|---|---|
| committer | Sasikanth Bharadwaj | 2017-11-29 08:44:17 +0000 |
| commit | f8ebd9dcd7fd27b8feb51794363d70a22ae2741f (patch) | |
| tree | a66a27604ad625725a8ec3687ab85c4024910713 | |
| parent | 70cab9868e721d0626b3815fdb9488585a05065f (diff) | |
| download | eclipse.jdt.core-f8ebd9dcd7fd27b8feb51794363d70a22ae2741f.tar.gz eclipse.jdt.core-f8ebd9dcd7fd27b8feb51794363d70a22ae2741f.tar.xz eclipse.jdt.core-f8ebd9dcd7fd27b8feb51794363d70a22ae2741f.zip | |
Fixed Bug 526132: Copy and paste the same function in a class gave NPEI20171129-2000
Change-Id: Ia85e4691dac2a4aa4d38844120c7b162be6b0237
2 files changed, 61 insertions, 3 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 e618727ac5..40e4aafb75 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, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2017 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 @@ -6201,5 +6201,63 @@ public void testBug526423() { } ); } +public void testBug526132() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + runNegativeTest( + new String[] { + "Test.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "public class Test {\n" + + " private Map field = new HashMap();\n" + + " private void method() {\n" + + " field.put(\"key\", \"value\");\n" + + " }\n" + + " private void method() {\n" + + " field.put(\"key\", \"value\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Test.java (at line 4)\n" + + " private Map field = new HashMap();\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map<K,V> should be parameterized\n" + + "----------\n" + + "2. WARNING in Test.java (at line 4)\n" + + " private Map field = new HashMap();\n" + + " ^^^^^^^\n" + + "HashMap is a raw type. References to generic type HashMap<K,V> should be parameterized\n" + + "----------\n" + + "3. ERROR in Test.java (at line 5)\n" + + " private void method() {\n" + + " ^^^^^^^^\n" + + "Duplicate method method() in type Test\n" + + "----------\n" + + "4. WARNING in Test.java (at line 5)\n" + + " private void method() {\n" + + " ^^^^^^^^\n" + + "The method method() from the type Test is never used locally\n" + + "----------\n" + + "5. WARNING in Test.java (at line 6)\n" + + " field.put(\"key\", \"value\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map<K,V> should be parameterized\n" + + "----------\n" + + "6. ERROR in Test.java (at line 8)\n" + + " private void method() {\n" + + " ^^^^^^^^\n" + + "Duplicate method method() in type Test\n" + + "----------\n" + + "7. WARNING in Test.java (at line 9)\n" + + " field.put(\"key\", \"value\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map<K,V> should be parameterized\n" + + "----------\n", + null, + true, + customOptions); +} } 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 0f925e778a..c37d1a0d44 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2017 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 @@ -1087,7 +1087,7 @@ 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 + if (methodDecl.binding != null && TypeBinding.notEquals(field.declaringClass, methodDecl.binding.declaringClass)) { // inherited raw field, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962 return true; } } else if (referenceContext instanceof TypeDeclaration) { |
