Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2013-03-14 13:31:57 +0000
committerStephan Herrmann2013-03-14 13:31:57 +0000
commit396f334c2ff7c977e0f293126ec531997e13ecfd (patch)
treeb95a92d9feab3903bcd3ed726df14f3b180d061c
parent33409dac2e3c76fa3d586662b269121c5d73c411 (diff)
downloadorg.eclipse.objectteams-396f334c2ff7c977e0f293126ec531997e13ecfd.tar.gz
org.eclipse.objectteams-396f334c2ff7c977e0f293126ec531997e13ecfd.tar.xz
org.eclipse.objectteams-396f334c2ff7c977e0f293126ec531997e13ecfd.zip
update jdt.core and .tests to I20130313-2000 (4.3 M6)
-rw-r--r--org.eclipse.jdt.core.tests.compiler/pom.xml4
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java28
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java27
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java114
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java11
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java79
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java7
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java42
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java232
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java410
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTestAsserts.java318
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java231
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java38
-rw-r--r--org.eclipse.jdt.core.tests.model/pom.xml4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java76
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java92
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java23
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java14
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests2.java55
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SelectionJavadocModelTests.java73
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyNotificationTests.java44
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java111
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Converter/src/javadoc/testBug347100/X.java12
-rw-r--r--org.eclipse.jdt.core/.settings/.api_filters23
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java25
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java14
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java13
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java13
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java28
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java10
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java12
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java10
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java15
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java9
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java206
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java25
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SuperReference.java11
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ThisReference.java14
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java18
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java15
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java9
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java232
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java104
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java72
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java16
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java59
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties6
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java4
-rw-r--r--org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetThisReference.java5
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAccessRule.java34
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAnnotatable.java6
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAnnotation.java6
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java9
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMethod.java58
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileInfo.java17
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java25
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/TypeHierarchy.java24
-rw-r--r--org.eclipse.jdt.core/pom.xml4
65 files changed, 2762 insertions, 463 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/pom.xml b/org.eclipse.jdt.core.tests.compiler/pom.xml
index 2d3a6d021..01c15c49f 100644
--- a/org.eclipse.jdt.core.tests.compiler/pom.xml
+++ b/org.eclipse.jdt.core.tests.compiler/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2012 Eclipse Foundation.
+ Copyright (c) 2012, 2013 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
@@ -18,7 +18,7 @@
<groupId>eclipse.jdt.core</groupId>
<version>3.8.0-SNAPSHOT</version>
</parent>
- <groupId>eclipse.jdt.core</groupId>
+ <groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core.tests.compiler</artifactId>
<version>3.8.2-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java
index a37199940..22685c160 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java
@@ -7,6 +7,8 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Stephan Herrmann - Contribution for
+ * bug 376590 - Private fields with @Inject are ignored by unused field validation
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -15,6 +17,32 @@ import junit.framework.Test;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
public class AbstractComparableTest extends AbstractRegressionTest {
+
+ protected static final String GOOGLE_INJECT_NAME = "com/google/inject/Inject.java";
+ protected static final String GOOGLE_INJECT_CONTENT =
+ "package com.google.inject;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "@Target({ METHOD, CONSTRUCTOR, FIELD })\n" +
+ "@Retention(RUNTIME)\n" +
+ "public @interface Inject {\n" +
+ "\n" +
+ " boolean optional() default false;\n" +
+ "}";
+
+ protected static final String JAVAX_INJECT_NAME = "javax/inject/Inject.java";
+ protected static final String JAVAX_INJECT_CONTENT =
+ "package javax.inject;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "@Target({ METHOD, CONSTRUCTOR, FIELD })\n" +
+ "@Retention(RUNTIME)\n" +
+ "public @interface Inject {}\n";
+
public static Test buildComparableTestSuite(Class evaluationTestClass) {
Test suite = buildMinimalComplianceTestSuite(evaluationTestClass, F_1_5);
TESTS_COUNTERS.put(evaluationTestClass.getName(), new Integer(suite.countTestCases()));
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
index 4e4c52e94..6833108a2 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -7,8 +7,9 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Stephan Herrmann - Contribution for bug 335093 - [compiler][null] minimal hook for future null annotation support
* Technical University Berlin - adapted for Object Teams
+ * Stephan Herrmann - Contribution for bug 335093 - [compiler][null] minimal hook for future null annotation support
+ * Jesper S Moller - Contributions for bug 378674 - "The method can be declared as static" is wrong
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -1197,6 +1198,28 @@ protected static class JavacTestOptions {
// javac options
JavacTestOptions.DEFAULT /* default javac test options */);
}
+ protected void runConformTest(String[] testFiles, Map customOptions) {
+ runTest(
+ // test directory preparation
+ true /* flush output directory */,
+ testFiles /* test files */,
+ // compiler options
+ null /* no class libraries */,
+ customOptions /* no custom options */,
+ false /* do not perform statements recovery */,
+ null /* no custom requestor */,
+ // compiler results
+ false /* expecting no compiler errors */,
+ null /* do not check compiler log */,
+ // runtime options
+ false /* do not force execution */,
+ null /* no vm arguments */,
+ // runtime results
+ null /* expected output string */,
+ null /* do not check error string */,
+ // javac options
+ JavacTestOptions.DEFAULT /* default javac test options */);
+ }
protected void runConformTest(
String[] testFiles,
String[] dependantFiles,
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
index 9608c0539..0c3182aaf 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
@@ -14,6 +14,7 @@
* bug 384663 - Package Based Annotation Compilation Error in JDT 3.8/4.2 (works in 3.7.2)
* bug 386356 - Type mismatch error with annotations and generics
* bug 331649 - [compiler][null] consider null annotations for fields
+ * bug 376590 - Private fields with @Inject are ignored by unused field validation
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -10520,6 +10521,119 @@ public void testBug365437f() {
"----------\n",
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
+
+// https://bugs.eclipse.org/376590 - Private fields with @Inject are ignored by unused field validation
+// using com.google.inject.Inject
+public void testBug376590a() {
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ this.runNegativeTest(
+ true,
+ new String[] {
+ GOOGLE_INJECT_NAME,
+ GOOGLE_INJECT_CONTENT,
+ "Example.java",
+ "import com.google.inject.Inject;\n" +
+ "class Example {\n" +
+ " private @Inject Object o;\n" +
+ " private @Inject Example() {}\n" + // no warning on constructor
+ " public Example(Object o) { this.o = o; }\n" +
+ " private @Inject void setO(Object o) { this.o = o;}\n" + // no warning on method
+ "}\n"
+ },
+ null, customOptions,
+ "----------\n" +
+ "1. ERROR in Example.java (at line 3)\n" +
+ " private @Inject Object o;\n" +
+ " ^\n" +
+ "The value of the field Example.o is not used\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
+// https://bugs.eclipse.org/376590 - Private fields with @Inject are ignored by unused field validation
+// using javax.inject.Inject - slight variation
+public void testBug376590b() {
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ this.runNegativeTest(
+ true,
+ new String[] {
+ JAVAX_INJECT_NAME,
+ JAVAX_INJECT_CONTENT,
+ "Example.java",
+ "class Example {\n" +
+ " private @javax.inject.Inject Object o;\n" +
+ " private Example() {} // also warn here: no @Inject\n" +
+ " public Example(Object o) { this.o = o; }\n" +
+ " private @javax.inject.Inject void setO(Object o) { this.o = o;}\n" +
+ "}\n"
+ },
+ null, customOptions,
+ "----------\n" +
+ "1. ERROR in Example.java (at line 2)\n" +
+ " private @javax.inject.Inject Object o;\n" +
+ " ^\n" +
+ "The value of the field Example.o is not used\n" +
+ "----------\n" +
+ "2. ERROR in Example.java (at line 3)\n" +
+ " private Example() {} // also warn here: no @Inject\n" +
+ " ^^^^^^^^^\n" +
+ "The constructor Example() is never used locally\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
+// https://bugs.eclipse.org/376590 - Private fields with @Inject are ignored by unused field validation
+// using javax.inject.Inject, combined with standard as well as custom annotations
+public void testBug376590c() {
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ customOptions.put(CompilerOptions.OPTION_AnnotationBasedNullAnalysis, CompilerOptions.ENABLED);
+ customOptions.put(CompilerOptions.OPTION_NonNullAnnotationName, "p.NonNull");
+ this.runNegativeTest(
+ true,
+ new String[] {
+ JAVAX_INJECT_NAME,
+ JAVAX_INJECT_CONTENT,
+ "Example.java",
+ "import javax.inject.Inject;\n" +
+ "class Example {\n" +
+ " private @Inject @p.NonNull Object o; // do warn, annotations don't signal a read\n" +
+ " private @Deprecated @Inject String old; // do warn, annotations don't signal a read\n" +
+ " private @Inject @p.Annot Object o2;\n" + // don't warn, custom annotation could imply a read access
+ "}\n",
+ "p/NonNull.java",
+ "package p;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.*;\n" +
+ "@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE,FIELD})\n" +
+ "public @interface NonNull {\n" +
+ "}",
+ "p/Annot.java",
+ "package p;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.*;\n" +
+ "@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE, CONSTRUCTOR, FIELD})\n" +
+ "public @interface Annot {\n" +
+ "}"
+ },
+ null, customOptions,
+ "----------\n" +
+ "1. ERROR in Example.java (at line 3)\n" +
+ " private @Inject @p.NonNull Object o; // do warn, annotations don't signal a read\n" +
+ " ^\n" +
+ "The value of the field Example.o is not used\n" +
+ "----------\n" +
+ "2. ERROR in Example.java (at line 4)\n" +
+ " private @Deprecated @Inject String old; // do warn, annotations don't signal a read\n" +
+ " ^^^\n" +
+ "The value of the field Example.old is not used\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
+
public void testBug376429a() {
this.runNegativeTest(
new String[] {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
index f81c551b7..5a6f5820e 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2012 IBM Corporation and others.
+ * Copyright (c) 2006, 2013 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
@@ -20,6 +20,7 @@
* bug 381443 - [compiler][null] Allow parameter widening from @NonNull to unannotated
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 382789 - [compiler][null] warn when syntactically-nonnull expression is compared against null
+ * bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -758,10 +759,12 @@ public void _test011_problem_categories() {
expectedProblemAttributes.put("NotVisibleMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("NotVisibleType", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("NullableFieldReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
+ expectedProblemAttributes.put("NullExpressionReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("NullLocalVariableComparisonYieldsFalse", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("NullLocalVariableInstanceofYieldsFalse", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("NullLocalVariableReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("NullSourceString", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
+ expectedProblemAttributes.put("NullUnboxing", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("NumericValueOutOfRange", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
expectedProblemAttributes.put("ObjectCannotBeGeneric", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
expectedProblemAttributes.put("ObjectCannotHaveSuperTypes", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
@@ -802,7 +805,9 @@ public void _test011_problem_categories() {
expectedProblemAttributes.put("PotentiallyUnclosedCloseable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("PotentiallyUnclosedCloseableAtExit", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("PotentialNullLocalVariableReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
+ expectedProblemAttributes.put("PotentialNullExpressionReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("PotentialNullMessageSendReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
+ expectedProblemAttributes.put("PotentialNullUnboxing", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("PublicClassMustMatchFileName", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("RawMemberTypeCannotBeParameterized", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("RawTypeReference", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW));
@@ -1558,10 +1563,12 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("NotVisibleMethod", SKIP);
expectedProblemAttributes.put("NotVisibleType", SKIP);
expectedProblemAttributes.put("NullableFieldReference", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_REFERENCE));
+ expectedProblemAttributes.put("NullExpressionReference", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_REFERENCE));
expectedProblemAttributes.put("NullLocalVariableComparisonYieldsFalse", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK));
expectedProblemAttributes.put("NullLocalVariableInstanceofYieldsFalse", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK));
expectedProblemAttributes.put("NullLocalVariableReference", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_REFERENCE));
expectedProblemAttributes.put("NullSourceString", SKIP);
+ expectedProblemAttributes.put("NullUnboxing", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_REFERENCE));
expectedProblemAttributes.put("NumericValueOutOfRange", SKIP);
expectedProblemAttributes.put("ObjectCannotBeGeneric", SKIP);
expectedProblemAttributes.put("ObjectCannotHaveSuperTypes", SKIP);
@@ -1601,7 +1608,9 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("PotentialHeapPollutionFromVararg", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION));
expectedProblemAttributes.put("PotentiallyUnclosedCloseable", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE));
expectedProblemAttributes.put("PotentiallyUnclosedCloseableAtExit", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE));
+ expectedProblemAttributes.put("PotentialNullExpressionReference", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE));
expectedProblemAttributes.put("PotentialNullLocalVariableReference", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE));
+ expectedProblemAttributes.put("PotentialNullUnboxing", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE));
expectedProblemAttributes.put("PotentialNullMessageSendReference", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE));
expectedProblemAttributes.put("PublicClassMustMatchFileName", SKIP);
expectedProblemAttributes.put("RawMemberTypeCannotBeParameterized", SKIP);
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java
index 4c1edd534..78c5e7ec9 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -9,6 +9,8 @@
* IBM Corporation - initial API and implementation
* Stephan Herrmann - Contribution for
* bug 393719 - [compiler] inconsistent warnings on iteration variables
+ * Jesper S Moller - Contribution for
+ * bug 401853 - Eclipse Java compiler creates invalid bytecode (java.lang.VerifyError)
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -2906,6 +2908,81 @@ public void test056() throws Exception {
"Zork cannot be resolved to a type\n" +
"----------\n");
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401853
+// Eclipse Java compiler creates invalid bytecode (java.lang.VerifyError)
+public void test057() throws Exception {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
+
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.ArrayList;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public static void main(String[] argv) {\n" +
+ " for (long l : new ArrayList<Long>()) {}\n" +
+ " }\n" +
+ "}",
+ },
+ "",
+ null,
+ true,
+ null,
+ options,
+ null);
+
+ String expectedOutput =
+ "public class X {\n" +
+ " \n" +
+ " // Method descriptor #6 ()V\n" +
+ " // Stack: 1, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [8]\n" +
+ " 4 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 3]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 5] local: this index: 0 type: X\n" +
+ " \n" +
+ " // Method descriptor #15 ([Ljava/lang/String;)V\n" +
+ " // Stack: 2, Locals: 2\n" +
+ " public static void main(java.lang.String[] argv);\n" +
+ " 0 new java.util.ArrayList [16]\n" +
+ " 3 dup\n" +
+ " 4 invokespecial java.util.ArrayList() [18]\n" +
+ " 7 invokevirtual java.util.ArrayList.iterator() : java.util.Iterator [19]\n" +
+ " 10 astore_1\n" +
+ " 11 goto 27\n" +
+ " 14 aload_1\n" +
+ " 15 invokeinterface java.util.Iterator.next() : java.lang.Object [23] [nargs: 1]\n" +
+ " 20 checkcast java.lang.Long [29]\n" +
+ " 23 invokevirtual java.lang.Long.longValue() : long [31]\n" +
+ " 26 pop2\n" +
+ " 27 aload_1\n" +
+ " 28 invokeinterface java.util.Iterator.hasNext() : boolean [35] [nargs: 1]\n" +
+ " 33 ifne 14\n" +
+ " 36 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 5]\n" +
+ " [pc: 36, line: 6]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 37] local: argv index: 0 type: java.lang.String[]\n";
+
+ File f = new File(OUTPUT_DIR + File.separator + "X.class");
+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
+ String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
+ int index = result.indexOf(expectedOutput);
+ if (index == -1 || expectedOutput.length() == 0) {
+ System.out.println(Util.displayString(result, 3));
+ }
+ if (index == -1) {
+ assertEquals("Wrong contents", expectedOutput, result);
+ }
+}
+
public static Class testClass() {
return ForeachStatementTest.class;
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
index 7a2739e06..b2bbe631a 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
@@ -38770,8 +38770,7 @@ public void test1132() {
" X myThing = new X<Object>();\n" +
" Integer i = myThing.getList().get(0); // Type Mismatch error - Since\n" +
" // myThing is unbounded, return\n" +
- " // type List<Integer>\n" +
- " // incorrectly becomes unbounded\n" +
+ " // type List<Integer> becomes unbounded\n" +
" }\n" +
"\n" +
" public List<Integer> getList() {\n" +
@@ -38803,12 +38802,12 @@ public void test1132() {
" ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Type mismatch: cannot convert from Object to Integer\n" +
"----------\n" +
- "3. WARNING in X.java (at line 25)\n" +
+ "3. WARNING in X.java (at line 24)\n" +
" X myThing = new X<Object>();\n" +
" ^\n" +
"X is a raw type. References to generic type X<T> should be parameterized\n" +
"----------\n" +
- "4. WARNING in X.java (at line 26)\n" +
+ "4. WARNING in X.java (at line 25)\n" +
" List<Integer> l = myThing.getList();\n" +
" ^^^^^^^^^^^^^^^^^\n" +
"Type safety: The expression of type List needs unchecked conversion to conform to List<Integer>\n" +
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 872104691..6b769ebdf 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
@@ -10,6 +10,7 @@
* Stephan Herrmann <stephan@cs.tu-berlin.de> - Contributions for
* bug 282152 - [1.5][compiler] Generics code rejected by Eclipse but accepted by javac
* bug 395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation.
+ * bug 401456 - Code compiles from javac/intellij, but fails from eclipse
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -30,7 +31,7 @@ public class GenericsRegressionTest extends AbstractComparableTest {
// Static initializer to specify tests subset using TESTS_* static variables
// All specified tests which does not belong to the class are skipped...
static {
-// TESTS_NAMES = new String[] { "testBug395002_combined" };
+// TESTS_NAMES = new String[] { "test401456" };
// TESTS_NAMES = new String[] { "test1464" };
// TESTS_NUMBERS = new int[] { 1465 };
// TESTS_RANGE = new int[] { 1097, -1 };
@@ -2817,4 +2818,43 @@ public void test397888b() {
"----------\n",
null, true, customOptions);
}
+// Bug 401456 - Code compiles from javac/intellij, but fails from eclipse
+public void test401456() {
+ runConformTest(
+ new String[] {
+ "App.java",
+ "import java.util.List;\n" +
+ "\n" +
+ "public class App {\n" +
+ "\n" +
+ " public interface Command_1<T> {\n" +
+ " public void execute(T o);\n" +
+ " }\n" +
+ " public static class ObservableEventWithArg<T> {\n" +
+ " public class Monitor {\n" +
+ " public Object addListener(final Command_1<T> l) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " public static class Context<T> {\n" +
+ " public ObservableEventWithArg<String>.Monitor getSubmissionErrorEventMonitor() {\n" +
+ " return new ObservableEventWithArg<String>().new Monitor();\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] args) {\n" +
+ " compileError(new Context<List<String>>());\n" +
+ " }\n" +
+ "\n" +
+ " private static void compileError(Context context) {\n" +
+ " context.getSubmissionErrorEventMonitor().addListener(\n" + // here the inner message send bogusly resolved to ObservableEventWithArg#RAW.Monitor
+ " new Command_1<String>() {\n" +
+ " public void execute(String o) {\n" +
+ " }\n" +
+ " });\n" +
+ " }\n" +
+ "}\n"
+ });
+}
} \ No newline at end of file
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 294e9135f..77908b218 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2012 GK Software AG and others.
+ * Copyright (c) 2010, 2013 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
@@ -53,7 +53,7 @@ public NullAnnotationTest(String name) {
// Static initializer to specify tests subset using TESTS_* static variables
// All specified tests which do not belong to the class are skipped...
static {
-// TESTS_NAMES = new String[] { "test_nullable_field_10e" };
+// TESTS_NAMES = new String[] { "test_conditional_expression" };
// TESTS_NUMBERS = new int[] { 561 };
// TESTS_RANGE = new int[] { 1, 2049 };
}
@@ -4262,6 +4262,87 @@ public void test_nonnull_field_14b() {
"");
}
+// A @NonNull field is assumed to be initialized by the injection framework
+// [compiler] Null analysis for fields does not take @com.google.inject.Inject into account
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400421
+public void test_nonnull_field_15() {
+ runConformTestWithLibs(
+ new String[] {
+ GOOGLE_INJECT_NAME,
+ GOOGLE_INJECT_CONTENT,
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import com.google.inject.Inject;\n" +
+ "public class X {\n" +
+ " @NonNull @Inject Object o;\n" +
+ " @NonNullByDefault class Inner {\n" +
+ " @Inject String s;\n" +
+ " }\n" +
+ "}\n",
+ },
+ null /*customOptions*/,
+ "");
+}
+
+// Injection is optional, don't rely on the framework
+// [compiler] Null analysis for fields does not take @com.google.inject.Inject into account
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400421
+public void test_nonnull_field_16() {
+ runNegativeTestWithLibs(
+ new String[] {
+ GOOGLE_INJECT_NAME,
+ GOOGLE_INJECT_CONTENT,
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import com.google.inject.Inject;\n" +
+ "public class X {\n" +
+ " @Inject(optional=true) @NonNull Object o;\n" +
+ " @NonNullByDefault class Inner {\n" +
+ " @Inject(optional=true) String s;\n" +
+ " @Inject(optional=false) String t;\n" + // don't complain here
+ " }\n" +
+ "}\n",
+ },
+ null /*customOptions*/,
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " @Inject(optional=true) @NonNull Object o;\n" +
+ " ^\n" +
+ "The @NonNull field o may not have been initialized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " @Inject(optional=true) String s;\n" +
+ " ^\n" +
+ "The @NonNull field s may not have been initialized\n" +
+ "----------\n");
+}
+
+// Using javax.inject.Inject, slight variations
+// [compiler] Null analysis for fields does not take @com.google.inject.Inject into account
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400421
+public void test_nonnull_field_17() {
+ runNegativeTestWithLibs(
+ new String[] {
+ JAVAX_INJECT_NAME,
+ JAVAX_INJECT_CONTENT,
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "import javax.inject.Inject;\n" +
+ "public class X {\n" +
+ " @NonNull @Inject static String s; // warn since injection of static field is less reliable\n" + // variation: static field
+ " @NonNull @Inject @Deprecated Object o;\n" +
+ " public X() {}\n" + // variation: with explicit constructor
+ "}\n",
+ },
+ null /*customOptions*/,
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " @NonNull @Inject static String s; // warn since injection of static field is less reliable\n" +
+ " ^\n" +
+ "The @NonNull field s may not have been initialized\n" +
+ "----------\n");
+}
+
// access to a nullable field - field reference
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649
public void test_nullable_field_1() {
@@ -5019,6 +5100,44 @@ public void test_nullable_field_14a() {
"----------\n");
}
+// https://bugs.eclipse.org/401017: [compiler][null] casted reference to @Nullable field lacks a warning
+public void test_nullable_field_15() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " @Nullable\n" +
+ " private Object nullable;\n" +
+ "\n" +
+ " public void test() {\n" +
+ " if (nullable instanceof Number) {\n" +
+ " ((Number)nullable).intValue(); // A\n" +
+ " }\n" +
+ " if (nullable != null) {\n" +
+ " nullable.toString(); // B\n" +
+ " }\n" +
+ " nullable.toString(); // C\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " ((Number)nullable).intValue(); // A\n" +
+ " ^^^^^^^^\n" +
+ "Potential null pointer access: The field nullable is declared as @Nullable\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 11)\n" +
+ " nullable.toString(); // B\n" +
+ " ^^^^^^^^\n" +
+ "Potential null pointer access: The field nullable is declared as @Nullable\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 13)\n" +
+ " nullable.toString(); // C\n" +
+ " ^^^^^^^^\n" +
+ "Potential null pointer access: The field nullable is declared as @Nullable\n" +
+ "----------\n");
+}
// an enum is declared within the scope of a null-default
// https://bugs.eclipse.org/331649#c61
public void test_enum_field_01() {
@@ -5899,6 +6018,113 @@ public void testBug388281_10() {
" ^^^^\n" +
"Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" +
"----------\n");
- }
+}
+
+// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
+// junit's assertNull vs. a @NonNull field / expression
+public void testBug382069_j() {
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.ERROR);
+ runNegativeTestWithLibs(
+ new String[] {
+ NullReferenceTestAsserts.JUNIT_ASSERT_NAME,
+ NullReferenceTestAsserts.JUNIT_ASSERT_CONTENT,
+ "X.java",
+ "import org.eclipse.jdt.annotation.NonNull;\n" +
+ "public class X {\n" +
+ " @NonNull String o1 = \"\";\n" +
+ " boolean foo() {\n" +
+ " junit.framework.Assert.assertNull(\"something's wrong\", o1);\n" + // always fails due to @NonNull
+ " return false; // dead code\n" +
+ " }\n" +
+ " void bar() {\n" +
+ " junit.framework.Assert.assertNull(\"\");\n" + // constantly false
+ " return; // dead code\n" +
+ " }\n" +
+ " void zork() {\n" +
+ " junit.framework.Assert.assertNotNull(null);\n" + // constantly false
+ " return; // dead code\n" +
+ " }\n" +
+ "}\n"},
+ options,
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " return false; // dead code\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "Dead code\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 10)\n" +
+ " return; // dead code\n" +
+ " ^^^^^^^\n" +
+ "Dead code\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 14)\n" +
+ " return; // dead code\n" +
+ " ^^^^^^^\n" +
+ "Dead code\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
+// junit's assertNonNull et al. affecting a @Nullable field using syntactic analysis
+public void testBug382069_k() {
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED);
+ options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.ERROR);
+ runNegativeTestWithLibs(
+ new String[] {
+ NullReferenceTestAsserts.JUNIT_ASSERT_NAME,
+ NullReferenceTestAsserts.JUNIT_ASSERT_CONTENT,
+ "X.java",
+ "import org.eclipse.jdt.annotation.Nullable;\n" +
+ "public class X {\n" +
+ " @Nullable String o1;\n" +
+ " int foo() {\n" +
+ " junit.framework.Assert.assertNotNull(\"something's wrong\", o1);\n" +
+ " return o1.length();\n" +
+ " }\n" +
+ " int bar(int i) {\n" +
+ " junit.framework.Assert.assertNotNull(o1);\n" +
+ " i++;\n" + // expire
+ " return o1.length(); // no longer protected\n" +
+ " }\n" +
+ " int garp() {\n" +
+ " junit.framework.Assert.assertFalse(\"something's wrong\", o1 == null);\n" +
+ " return o1.length();\n" +
+ " }\n" +
+ " int zipp() {\n" +
+ " junit.framework.Assert.assertTrue(\"something's wrong\", o1 != null);\n" +
+ " return o1.length();\n" +
+ " }\n" +
+ "}\n"},
+ options,
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " return o1.length(); // no longer protected\n" +
+ " ^^\n" +
+ "Potential null pointer access: The field o1 is declared as @Nullable\n" +
+ "----------\n");
+}
+//https://bugs.eclipse.org/400761: [compiler][null] null may be return as boolean without a diagnostic
+public void test_conditional_expression_1() {
+ runNegativeTestWithLibs(
+ new String[] {
+ "X.java",
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "public class X {\n" +
+ " boolean badFunction5(int i) {\n" +
+ " // expected a potential null problem:\n" +
+ " return i > 0 ? true : getBoolean();\n" +
+ " }\n" +
+ " private @Nullable Boolean getBoolean() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " return i > 0 ? true : getBoolean();\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" +
+ "----------\n");
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
index 6245e577c..534609920 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 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
@@ -27,6 +27,9 @@
* bug 376263 - Bogus "Potential null pointer access" warning
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 382789 - [compiler][null] warn when syntactically-nonnull expression is compared against null
+ * bug 401088 - [compiler][null] Wrong warning "Redundant null check" inside nested try statement
+ * bug 401092 - [compiler][null] Wrong warning "Redundant null check" in outer catch of nested try
+ * bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -55,9 +58,9 @@ public NullReferenceTest(String name) {
// Only the highest compliance level is run; add the VM argument
// -Dcompliance=1.4 (for example) to lower it if needed
static {
-// TESTS_NAMES = new String[] { "testBug345305_14" };
+// TESTS_NAMES = new String[] { "test0037_conditional_expression" };
// TESTS_NAMES = new String[] { "test0515_try_finally" };
-// TESTS_NAMES = new String[] { "testBug376263" };
+// TESTS_NAMES = new String[] { "testBug319201c" };
// TESTS_NUMBERS = new int[] { 561 };
// TESTS_RANGE = new int[] { 1, 2049 };
}
@@ -886,6 +889,141 @@ public void test0036_conditional_expression() {
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
+// https://bugs.eclipse.org/400761: [compiler][null] null may be return as boolean without a diagnostic
+public void test0037_conditional_expression_1() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // needs autoboxing
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " boolean badFunction(int i) {\n" +
+ " return i > 0 ? true : null;\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " return i > 0 ? true : null;\n" +
+ " ^^^^^^^^^^^^^^^^^^^\n" +
+ "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
+// https://bugs.eclipse.org/400761: [compiler][null] null may be return as boolean without a diagnostic
+public void test0037_conditional_expression_2() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // needs autoboxing
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, JavaCore.ENABLED);
+ runNegativeTest(
+ true,
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " int badFunction(int i) {\n" +
+ " return i > 0 ? null : Integer.MIN_VALUE;\n" +
+ " }\n" +
+ " @SuppressWarnings(\"null\")\n" +
+ " int silent(int i) {\n" +
+ " return i > 0 ? null : Integer.MIN_VALUE;\n" +
+ " }\n" +
+ "}\n"},
+ null,
+ options,
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " return i > 0 ? null : Integer.MIN_VALUE;\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
+//https://bugs.eclipse.org/400761: [compiler][null] null may be return as boolean without a diagnostic
+public void test0037_conditional_expression_3() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // needs autoboxing
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR);
+ runNegativeTest(
+ true,
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " boolean badFunction3(int i) {\n" +
+ " //expected a potential null problem:\n" +
+ " return i > 0 ? true : (Boolean) null;\n" +
+ " }\n" +
+ "}\n"},
+ null,
+ options,
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " return i > 0 ? true : (Boolean) null;\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
+// https://bugs.eclipse.org/400761: [compiler][null] null may be return as boolean without a diagnostic
+// if-then-else instead of conditional expression
+public void test0037_conditional_expression_4() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // needs autoboxing
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR);
+ options.put(JavaCore.COMPILER_PB_UNNECESSARY_ELSE, JavaCore.IGNORE);
+ runNegativeTest(
+ true,
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " boolean badFunction4(int i) {\n" +
+ " if (i > 0)\n" +
+ " return true;\n" +
+ " else\n" +
+ " // expected a null problem:\n" +
+ " return (Boolean) null;\n" +
+ " }\n" +
+ "}\n"},
+ null,
+ options,
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " return (Boolean) null;\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
+// https://bugs.eclipse.org/400761: [compiler][null] null may be return as boolean without a diagnostic
+// pot-null cond-expr in receiver position
+public void test0037_conditional_expression_5() {
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR);
+ runNegativeTest(
+ true,
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " String badFunction3(int i) {\n" +
+ " return (i > 0 ? this : null).toString();\n" +
+ " }\n" +
+ " String badFunction4(int i) {\n" +
+ " Object o = null;\n" +
+ " return (i > 0 ? o : null).toString();\n" +
+ " }\n" +
+ "}\n"},
+ null,
+ options,
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " return (i > 0 ? this : null).toString();\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Potential null pointer access: This expression may be null\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " return (i > 0 ? o : null).toString();\n" +
+ " ^^^^^^^^^^^^^^^^^^\n" +
+ "Null pointer access: This expression can only be null\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
// null analysis -- autoboxing
public void test0040_autoboxing_compound_assignment() {
if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
@@ -902,7 +1040,7 @@ public void test0040_autoboxing_compound_assignment() {
"1. ERROR in X.java (at line 4)\n" +
" i += 1;\n" +
" ^\n" +
- "Null pointer access: The variable i can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n",
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
@@ -925,7 +1063,7 @@ public void test0041_autoboxing_increment_operator() {
"1. ERROR in X.java (at line 4)\n" +
" i++;\n" +
" ^\n" +
- "Null pointer access: The variable i can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n",
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
@@ -974,7 +1112,7 @@ public void test0043_autoboxing_literal() {
"1. ERROR in X.java (at line 4)\n" +
" System.out.println(i + 4);\n" +
" ^\n" +
- "Null pointer access: The variable i can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n",
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
@@ -11622,12 +11760,12 @@ public void testBug253896a() {
"1. ERROR in X.java (at line 4)\n" +
" if(f1 == 1)\n" +
" ^^\n" +
- "Null pointer access: The variable f1 can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n" +
"2. ERROR in X.java (at line 7)\n" +
" int abc = (f2 != 1)? 1 : 0;\n" +
" ^^\n" +
- "Null pointer access: The variable f2 can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n" +
"3. ERROR in X.java (at line 9)\n" +
" if(f3 == null)\n" +
@@ -11668,12 +11806,12 @@ public void testBug253896b() {
"1. ERROR in X.java (at line 4)\n" +
" if(i1 == 1)\n" +
" ^^\n" +
- "Null pointer access: The variable i1 can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n" +
"2. ERROR in X.java (at line 7)\n" +
" if(i1 == 0) {}\n" +
" ^^\n" +
- "Potential null pointer access: The variable i1 may be null at this location\n" +
+ "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" +
"----------\n");
}
}
@@ -11711,12 +11849,12 @@ public void testBug253896c() {
"1. ERROR in X.java (at line 7)\n" +
" if(f1 == 1)\n" +
" ^^\n" +
- "Null pointer access: The variable f1 can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n" +
"2. ERROR in X.java (at line 10)\n" +
" int abc = (f2 != 1)? 1 : 0;\n" +
" ^^\n" +
- "Null pointer access: The variable f2 can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n" +
"3. ERROR in X.java (at line 12)\n" +
" if(f3 == null)\n" +
@@ -11736,12 +11874,12 @@ public void testBug253896c() {
"6. ERROR in X.java (at line 17)\n" +
" if(a == 1) {}\n" +
" ^\n" +
- "Null pointer access: The variable a can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n" +
"7. ERROR in X.java (at line 18)\n" +
" if(outer2 == 1) {}\n" +
" ^^^^^^\n" +
- "Potential null pointer access: The variable outer2 may be null at this location\n" +
+ "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" +
"----------\n");
}
}
@@ -11779,12 +11917,12 @@ public void testBug253896d() {
"1. ERROR in X.java (at line 8)\n" +
" if(f1 == 1)\n" +
" ^^\n" +
- "Null pointer access: The variable f1 can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n" +
"2. ERROR in X.java (at line 11)\n" +
" int abc = (f2 != 1)? 1 : 0;\n" +
" ^^\n" +
- "Null pointer access: The variable f2 can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n" +
"3. ERROR in X.java (at line 13)\n" +
" if(f3 == null)\n" +
@@ -11804,12 +11942,12 @@ public void testBug253896d() {
"6. ERROR in X.java (at line 18)\n" +
" if(outer == 1) {}\n" +
" ^^^^^\n" +
- "Null pointer access: The variable outer can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n" +
"7. ERROR in X.java (at line 19)\n" +
" if(param == 1) {}\n" +
" ^^^^^\n" +
- "Potential null pointer access: The variable param may be null at this location\n" +
+ "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" +
"----------\n");
}
}
@@ -12162,7 +12300,7 @@ public void testBug319201() {
"1. ERROR in X.java (at line 4)\n" +
" int j = i;\n" +
" ^\n" +
- "Null pointer access: The variable i can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n",
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
@@ -12186,7 +12324,7 @@ public void testBug319201a() {
"1. ERROR in X.java (at line 5)\n" +
" j = i;\n" +
" ^\n" +
- "Potential null pointer access: The variable i may be null at this location\n" +
+ "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" +
"----------\n",
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
@@ -12210,7 +12348,7 @@ public void testBug319201b() {
"1. ERROR in X.java (at line 4)\n" +
" bar(bo);\n" +
" ^^\n" +
- "Null pointer access: The variable bo can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n",
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
@@ -12283,72 +12421,77 @@ public void testBug319201c() {
"1. ERROR in X.java (at line 4)\n" +
" super(b2 == null, b2);\n" +
" ^^\n" +
- "Potential null pointer access: The variable b2 may be null at this location\n" +
+ "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" +
"----------\n" +
- "2. ERROR in X.java (at line 12)\n" +
+ "2. ERROR in X.java (at line 9)\n" +
+ " boolean fB = (Boolean)null;\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 12)\n" +
" X x = new X(b1, null);\n" +
" ^^\n" +
- "Null pointer access: The variable b1 can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n" +
- "3. ERROR in X.java (at line 14)\n" +
+ "4. ERROR in X.java (at line 14)\n" +
" boolean dontcare = b2 && inB;\n" +
" ^^\n" +
- "Null pointer access: The variable b2 can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n" +
- "4. ERROR in X.java (at line 16)\n" +
+ "5. ERROR in X.java (at line 16)\n" +
" dontcare = inB || b3;\n" +
" ^^\n" +
- "Null pointer access: The variable b3 can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n" +
- "5. ERROR in X.java (at line 18)\n" +
+ "6. ERROR in X.java (at line 18)\n" +
" char[] cs = new char[dims];\n" +
" ^^^^\n" +
- "Null pointer access: The variable dims can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n" +
- "6. ERROR in X.java (at line 22)\n" +
+ "7. ERROR in X.java (at line 22)\n" +
" for (int i=0;b4; i++);\n" +
" ^^\n" +
- "Null pointer access: The variable b4 can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n" +
- "7. ERROR in X.java (at line 23)\n" +
+ "8. ERROR in X.java (at line 23)\n" +
" } while (b5);\n" +
" ^^\n" +
- "Null pointer access: The variable b5 can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n" +
- "8. ERROR in X.java (at line 25)\n" +
+ "9. ERROR in X.java (at line 25)\n" +
" if (b6) { }\n" +
" ^^\n" +
- "Null pointer access: The variable b6 can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n" +
- "9. ERROR in X.java (at line 27)\n" +
+ "10. ERROR in X.java (at line 27)\n" +
" Z z = this.new Z(b7);\n" +
" ^^\n" +
- "Null pointer access: The variable b7 can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n" +
- "10. ERROR in X.java (at line 29)\n" +
+ "11. ERROR in X.java (at line 29)\n" +
" switch(sel) {\n" +
" ^^^\n" +
- "Null pointer access: The variable sel can only be null at this location\n" +
+ "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" +
"----------\n" +
- "11. ERROR in X.java (at line 34)\n" +
+ "12. ERROR in X.java (at line 34)\n" +
" while (b8) {}\n" +
" ^^\n" +
- "Null pointer access: The variable b8 can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n" +
- "12. ERROR in X.java (at line 36)\n" +
+ "13. ERROR in X.java (at line 36)\n" +
" dontcare = (boolean)b9;\n" +
" ^^\n" +
- "Null pointer access: The variable b9 can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n" +
- "13. ERROR in X.java (at line 38)\n" +
+ "14. ERROR in X.java (at line 38)\n" +
" assert b10 : \"shouldn\'t happen, but will\";\n" +
" ^^^\n" +
- "Null pointer access: The variable b10 can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n" +
- "14. ERROR in X.java (at line 40)\n" +
+ "15. ERROR in X.java (at line 40)\n" +
" return b11;\n" +
" ^^^\n" +
- "Null pointer access: The variable b11 can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n",
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
@@ -12411,17 +12554,17 @@ public void testBug319201d() {
"1. ERROR in X.java (at line 12)\n" +
" } while (b2);\n" +
" ^^\n" +
- "Potential null pointer access: The variable b2 may be null at this location\n" +
+ "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" +
"----------\n" +
"2. ERROR in X.java (at line 15)\n" +
" } while (b3);\n" +
" ^^\n" +
- "Null pointer access: The variable b3 can only be null at this location\n" +
+ "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" +
"----------\n" +
"3. ERROR in X.java (at line 42)\n" +
" } while (b7);\n" +
" ^^\n" +
- "Potential null pointer access: The variable b7 may be null at this location\n" +
+ "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" +
"----------\n",
null/*classLibraries*/,
true/*shouldFlushOutputDirectory*/,
@@ -16210,4 +16353,169 @@ public void testBug345305_14() {
"Potential null pointer access: The variable s may be null at this location\n" +
"----------\n");
}
+// Bug 401088 - [compiler][null] Wrong warning "Redundant null check" inside nested try statement
+public void testBug401088() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ "\n" +
+ " private static void occasionallyThrowException() throws Exception {\n" +
+ " throw new Exception();\n" +
+ " }\n" +
+ "\n" +
+ " private static void open() throws Exception {\n" +
+ " occasionallyThrowException();\n" +
+ " }\n" +
+ "\n" +
+ " private static void close() throws Exception {\n" +
+ " occasionallyThrowException();\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String s[]) {\n" +
+ " Exception exc = null;\n" +
+ " try {\n" +
+ " open();\n" +
+ " // do more things\n" +
+ " }\n" +
+ " catch (Exception e) {\n" +
+ " exc = e;\n" +
+ " }\n" +
+ " finally {\n" +
+ " try {\n" +
+ " close();\n" +
+ " }\n" +
+ " catch (Exception e) {\n" +
+ " if (exc == null) // should not warn on this line\n" +
+ " exc = e;\n" +
+ " }\n" +
+ " }\n" +
+ " if (exc != null)\n" +
+ " System.out.println(exc);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "java.lang.Exception");
+}
+// Bug 401088 - [compiler][null] Wrong warning "Redundant null check" inside nested try statement
+public void testBug401088a() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ "\n" +
+ " private static void occasionallyThrowException() throws Exception {\n" +
+ " throw new Exception();\n" +
+ " }\n" +
+ "\n" +
+ " private static void open() throws Exception {\n" +
+ " occasionallyThrowException();\n" +
+ " }\n" +
+ "\n" +
+ " private static void close() throws Exception {\n" +
+ " occasionallyThrowException();\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String s[]) {\n" +
+ " Exception exc = null;\n" +
+ " try {\n" +
+ " open();\n" +
+ " // do more things\n" +
+ " }\n" +
+ " catch (Exception e) {\n" +
+ " exc = e;\n" +
+ " }\n" +
+ " finally {\n" +
+ " try {\n" +
+ " close();\n" +
+ " }\n" +
+ " catch (Exception e) {\n" +
+ " if (exc == null) // should not warn on this line\n" +
+ " exc = e;\n" +
+ " }\n" +
+ " finally { System.out.print(1); }\n" +
+ " }\n" +
+ " if (exc != null)\n" +
+ " System.out.println(exc);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "1java.lang.Exception");
+}
+// Bug 401092 - [compiler][null] Wrong warning "Redundant null check" in outer catch of nested try
+public void test401092() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.Date;\n" +
+ "\n" +
+ "public class X {\n" +
+ "\n" +
+ " private static void occasionallyThrowException() throws Exception {\n" +
+ " throw new Exception();\n" +
+ " }\n" +
+ "\n" +
+ " private static Date createDate() throws Exception {\n" +
+ " occasionallyThrowException();\n" +
+ " return new Date();\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String s[]) {\n" +
+ " Date d = null;\n" +
+ " try {\n" +
+ " d = createDate();\n" +
+ " System.out.println(d.toString());\n" +
+ " try {\n" +
+ " occasionallyThrowException();\n" +
+ " }\n" +
+ " catch (Exception exc) {\n" +
+ " }\n" +
+ " }\n" +
+ " catch (Exception exc) {\n" +
+ " if (d != null) // should not warn in this line\n" +
+ " System.out.println(d.toString());\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ });
+}
+// Bug 401092 - [compiler][null] Wrong warning "Redundant null check" in outer catch of nested try
+public void test401092a() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.Date;\n" +
+ "\n" +
+ "public class X {\n" +
+ "\n" +
+ " private static void occasionallyThrowException() throws Exception {\n" +
+ " throw new Exception();\n" +
+ " }\n" +
+ "\n" +
+ " private static Date createDate() throws Exception {\n" +
+ " occasionallyThrowException();\n" +
+ " return new Date();\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String s[]) {\n" +
+ " Date d = null;\n" +
+ " try {\n" +
+ " d = createDate();\n" +
+ " System.out.println(d.toString());\n" +
+ " try {\n" +
+ " occasionallyThrowException();\n" +
+ " }\n" +
+ " catch (Exception exc) {\n" +
+ " }\n" +
+ " finally { System.out.println(1); }\n" +
+ " }\n" +
+ " catch (Exception exc) {\n" +
+ " if (d != null) // should not warn in this line\n" +
+ " System.out.println(d.toString());\n" +
+ " }\n" +
+ " finally { System.out.println(2); }\n" +
+ " }\n" +
+ "}\n"
+ });
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTestAsserts.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTestAsserts.java
index 98df5230c..82cb7cfa3 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTestAsserts.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTestAsserts.java
@@ -1,12 +1,14 @@
/*******************************************************************************
- * Copyright (c) 2012 IBM Corporation and others.
+ * Copyright (c) 2013 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Corporation - initial API and implementation
+ * IBM Corporation - initial API and implementation
+ * Stephan Herrmann - Contribution for
+ * bug 382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -35,11 +37,74 @@ public NullReferenceTestAsserts(String name) {
// Only the highest compliance level is run; add the VM argument
// -Dcompliance=1.4 (for example) to lower it if needed
static {
-// TESTS_NAMES = new String[] { "testBug373953" };
+// TESTS_NAMES = new String[] { "testBug382069" };
// TESTS_NUMBERS = new int[] { 561 };
// TESTS_RANGE = new int[] { 1, 2049 };
}
+static final String JUNIT_ASSERT_NAME = "junit/framework/Assert.java";
+static final String JUNIT_ASSERT_CONTENT = "package junit.framework;\n" +
+ "public class Assert {\n" +
+ " static public void assertNull(Object object) {}\n" +
+ " static public void assertNull(String message, Object object) {}\n" +
+ " static public void assertNotNull(Object object) {}\n" +
+ " static public void assertNotNull(String message, Object object) {}\n" +
+ " static public void assertTrue(boolean expression) {}\n" +
+ " static public void assertTrue(String message, boolean expression) {}\n" +
+ " static public void assertFalse(boolean expression) {}\n" +
+ " static public void assertFalse(String message, boolean expression) {}\n" +
+ "}\n";
+
+static final String ORG_JUNIT_ASSERT_NAME = "org/junit/Assert.java";
+static final String ORG_JUNIT_ASSERT_CONTENT = "package org.junit;\n" +
+ "public class Assert {\n" +
+ " static public void assertNull(Object object) {}\n" +
+ " static public void assertNull(String message, Object object) {}\n" +
+ " static public void assertNotNull(Object object) {}\n" +
+ " static public void assertNotNull(String message, Object object) {}\n" +
+ " static public void assertTrue(boolean expression) {}\n" +
+ " static public void assertTrue(String message, boolean expression) {}\n" +
+ " static public void assertFalse(boolean expression) {}\n" +
+ " static public void assertFalse(String message, boolean expression) {}\n" +
+ "}\n";
+
+static final String APACHE_VALIDATE_NAME = "org/apache/commons/lang/Validate.java";
+static final String APACHE_VALIDATE_CONTENT = "package org.apache.commons.lang;\n" +
+ "public class Validate {\n" +
+ " static public void notNull(Object object) {}\n" +
+ " static public void notNull(Object object, String message) {}\n" +
+ " static public void isTrue(boolean expression) {}\n" +
+ " static public void isTrue(boolean expression, String message) {}\n" +
+ " static public void isTrue(boolean expression, String message, double value) {}\n" +
+ " static public void isTrue(boolean expression, String message, long value) {}\n" +
+ " static public void isTrue(boolean expression, String message, Object value) {}\n" +
+ "}\n";
+
+static final String APACHE_3_VALIDATE_NAME = "org/apache/commons/lang3/Validate.java";
+static final String APACHE_3_VALIDATE_CONTENT = "package org.apache.commons.lang3;\n" +
+ "public class Validate {\n" +
+ " static public <T> T notNull(T object) { return object; }\n" +
+ " static public <T> T notNull(T object, String message, Object... values) { return object; }\n" +
+ " static public void isTrue(boolean expression) {}\n" +
+ " static public void isTrue(boolean expression, String message, double value) {}\n" +
+ " static public void isTrue(boolean expression, String message, long value) {}\n" +
+ " static public void isTrue(boolean expression, String message, Object value) {}\n" +
+ "}\n";
+
+static final String GOOGLE_PRECONDITIONS_NAME = "com/google/common/base/Preconditions.java";
+static final String GOOGLE_PRECONDITIONS_CONTENT = "package com.google.common.base;\n" +
+ "public class Preconditions {\n" +
+ " static public <T> T checkNotNull(T object) { return object; }\n" +
+ " static public <T> T checkNotNull(T object, Object message) { return object; }\n" +
+ " static public <T> T checkNotNull(T object, String message, Object... values) { return object; }\n" +
+ " static public void checkArgument(boolean expression) {}\n" +
+ " static public void checkArgument(boolean expression, Object message) {}\n" +
+ " static public void checkArgument(boolean expression, String msgTmpl, Object... messageArgs) {}\n" +
+ " static public void checkState(boolean expression) {}\n" +
+ " static public void checkState(boolean expression, Object message) {}\n" +
+ " static public void checkState(boolean expression, String msgTmpl, Object... messageArgs) {}\n" +
+ "}\n";
+
public static Test suite() {
return buildAllCompliancesTestSuite(testClass());
}
@@ -91,7 +156,7 @@ public void testBug127575a() throws IOException {
"}\n"},
"",
this.assertLib,
- false,
+ true,
null);
}
@@ -751,4 +816,249 @@ public void testBug373953() throws IOException {
"Potential null pointer access: The variable o may be null at this location\n" +
"----------\n");
}
+
+// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
+// junit's assertNotNull
+public void testBug382069a() throws IOException {
+ this.runConformTest(
+ new String[] {
+ JUNIT_ASSERT_NAME,
+ JUNIT_ASSERT_CONTENT,
+ "X.java",
+ "public class X {\n" +
+ " void foo(Object o1, String o2) {\n" +
+ " boolean b = o1 != null;\n" + // sheds doubts upon o1
+ " junit.framework.Assert.assertNotNull(o1);\n" + // protection
+ " o1.toString();\n" + // quiet
+ " b = o2 != null;\n" + // sheds doubts upon o2
+ " junit.framework.Assert.assertNotNull(\"msg\", o2);\n" + // protection
+ " o2.toString();\n" + // quiet
+ " }\n" +
+ "}\n"},
+ "");
+}
+
+// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
+// org.eclipse.core.runtime.Assert.isNotNull
+public void testBug382069b() {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void foo(Object o1, String o2) {\n" +
+ " boolean b = o1 != null;\n" + // sheds doubts upon o1
+ " org.eclipse.core.runtime.Assert.isNotNull(o1);\n" + // protection
+ " o1.toString();\n" + // quiet
+ " b = o2 != null;\n" + // sheds doubts upon o2
+ " org.eclipse.core.runtime.Assert.isNotNull(o2, \"msg\");\n" + // protection
+ " o2.toString();\n" + // quiet
+ " }\n" +
+ "}"
+ },
+ "",
+ this.assertLib,
+ true,
+ null);
+ }
+}
+
+// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
+// junit's assertNull and dead code analysis
+public void testBug382069c() throws IOException {
+ this.runNegativeTest(
+ new String[] {
+ JUNIT_ASSERT_NAME,
+ JUNIT_ASSERT_CONTENT,
+ "X.java",
+ "public class X {\n" +
+ " boolean foo(String o1, String o2) {\n" +
+ " junit.framework.Assert.assertNull(\"something's wrong\", o1);\n" + // establish nullness
+ " if (o2 == null)\n" +
+ " return o1 != null;\n" +
+ " junit.framework.Assert.assertNull(o2);\n" + // will always throw
+ " return false; // dead code\n" +
+ " }\n" +
+ " void bar(X x) {\n" +
+ " if (x == null) {\n" +
+ " junit.framework.Assert.assertNotNull(x);\n" +
+ " return; // dead code\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " return o1 != null;\n" +
+ " ^^\n" +
+ "Null comparison always yields false: The variable o1 can only be null at this location\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 7)\n" +
+ " return false; // dead code\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "Dead code\n" +
+ "----------\n" +
+ "3. WARNING in X.java (at line 12)\n" +
+ " return; // dead code\n" +
+ " ^^^^^^^\n" +
+ "Dead code\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
+// various asserts from org.apache.commons.lang.Validate
+public void testBug382069d() throws IOException {
+ this.runNegativeTest(
+ new String[] {
+ APACHE_VALIDATE_NAME,
+ APACHE_VALIDATE_CONTENT,
+ "X.java",
+ "import org.apache.commons.lang.Validate;\n" +
+ "public class X {\n" +
+ " void foo(Object o1, String o2, X x) {\n" +
+ " boolean b = o1 != null;\n" + // sheds doubts upon o1
+ " Validate.notNull(o1);\n" + // protection
+ " o1.toString();\n" + // quiet
+ " b = o2 != null;\n" + // sheds doubts upon o2
+ " Validate.notNull(o2, \"msg\");\n" + // protection
+ " o2.toString();\n" + // quiet
+ " Validate.isTrue(x == null, \"ups\", x);\n" +
+ " x.foo(null, null, null); // definite NPE\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " x.foo(null, null, null); // definite NPE\n" +
+ " ^\n" +
+ "Null pointer access: The variable x can only be null at this location\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
+// various asserts from org.apache.commons.lang3Validate
+public void testBug382069e() throws IOException {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
+ this.runNegativeTest(
+ new String[] {
+ APACHE_3_VALIDATE_NAME,
+ APACHE_3_VALIDATE_CONTENT,
+ "X.java",
+ "import org.apache.commons.lang3.Validate;\n" +
+ "public class X {\n" +
+ " void foo(Object o1, String o2, X x) {\n" +
+ " boolean b = o1 != null;\n" + // sheds doubts upon o1
+ " Validate.notNull(o1);\n" + // protection
+ " o1.toString();\n" + // quiet
+ " b = o2 != null;\n" + // sheds doubts upon o2
+ " Validate.notNull(o2, \"msg\");\n" + // protection
+ " o2.toString();\n" + // quiet
+ " Validate.isTrue(x == null, \"ups\", x);\n" +
+ " x.foo(null, null, null); // definite NPE\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " x.foo(null, null, null); // definite NPE\n" +
+ " ^\n" +
+ "Null pointer access: The variable x can only be null at this location\n" +
+ "----------\n");
+ }
+}
+// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
+// various asserts from com.google.common.base.Preconditions
+public void testBug382069f() throws IOException {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
+ this.runNegativeTest(
+ new String[] {
+ GOOGLE_PRECONDITIONS_NAME,
+ GOOGLE_PRECONDITIONS_CONTENT,
+ "X.java",
+ "import com.google.common.base.Preconditions;\n" +
+ "public class X {\n" +
+ " void foo(Object o1, String o2, X x) {\n" +
+ " boolean b = o1 != null;\n" + // sheds doubts upon o1
+ " Preconditions.checkNotNull(o1);\n" + // protection
+ " o1.toString();\n" + // quiet
+ " b = o2 != null;\n" + // sheds doubts upon o2
+ " Preconditions.checkNotNull(o2, \"msg {0}.{1}\", o1, o2);\n" + // protection
+ " o2.toString();\n" + // quiet
+ " Preconditions.checkArgument(x == null, \"ups\");\n" +
+ " x.foo(null, null, null); // definite NPE\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " x.foo(null, null, null); // definite NPE\n" +
+ " ^\n" +
+ "Null pointer access: The variable x can only be null at this location\n" +
+ "----------\n");
+ }
+}
+// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
+// java.util.Objects#requireNonNull
+public void testBug382069g() throws IOException {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_7) {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import static java.util.Objects.requireNonNull;\n" +
+ "public class X {\n" +
+ " void foo(Object o1, String o2, X x) {\n" +
+ " boolean b = o1 != null;\n" + // sheds doubts upon o1
+ " requireNonNull(o1);\n" + // protection
+ " o1.toString();\n" + // quiet
+ " b = o2 != null;\n" + // sheds doubts upon o2
+ " requireNonNull(o2, \"msg\");\n" + // protection
+ " o2.toString();\n" + // quiet
+ " }\n" +
+ "}\n"},
+ "");
+ }
+}
+
+// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
+// junit's assertTrue / assertFalse
+public void testBug382069h() throws IOException {
+ this.runConformTest(
+ new String[] {
+ JUNIT_ASSERT_NAME,
+ JUNIT_ASSERT_CONTENT,
+ "X.java",
+ "public class X {\n" +
+ " void foo(Object o1, String o2) {\n" +
+ " boolean b = o1 != null;\n" + // sheds doubts upon o1
+ " junit.framework.Assert.assertTrue(o1 != null);\n" + // protection
+ " o1.toString();\n" + // quiet
+ " b = o2 != null;\n" + // sheds doubts upon o2
+ " junit.framework.Assert.assertFalse(\"msg\", o2 == null);\n" + // protection
+ " o2.toString();\n" + // quiet
+ " }\n" +
+ "}\n"},
+ "");
+}
+// Bug 401159 - [null] Respect org.junit.Assert for control flow
+// various asserts from org.junit.Assert
+public void testBug401159() throws IOException {
+ this.runNegativeTest(
+ new String[] {
+ ORG_JUNIT_ASSERT_NAME,
+ ORG_JUNIT_ASSERT_CONTENT,
+ "X.java",
+ "import org.junit.Assert;\n" +
+ "public class X {\n" +
+ " void foo(Object o1, String o2, X x) {\n" +
+ " boolean b = o1 != null;\n" + // sheds doubts upon o1
+ " Assert.assertNotNull(o1);\n" + // protection
+ " o1.toString();\n" + // quiet
+ " b = o2 != null;\n" + // sheds doubts upon o2
+ " Assert.assertNotNull(\"msg\", o2);\n" + // protection
+ " o2.toString();\n" + // quiet
+ " Assert.assertTrue(\"ups\", x == null);\n" +
+ " x.foo(null, null, null); // definite NPE\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " x.foo(null, null, null); // definite NPE\n" +
+ " ^\n" +
+ "Null pointer access: The variable x can only be null at this location\n" +
+ "----------\n");
+}
}
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 9162aa692..5ef1b365a 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -11,6 +11,8 @@
* bug 328281 - visibility leaks not detected when analyzing unused field in private class
* bug 379784 - [compiler] "Method can be static" is not getting reported
* bug 379834 - Wrong "method can be static" in presence of qualified super and different staticness of nested super class.
+ * Jesper S Moller <jesper@selskabet.org> - Contributions for
+ * bug 378674 - "The method can be declared as static" is wrong
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -8145,4 +8147,231 @@ public void test393781() {
compilerOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, oldOption);
}
}
+private void runStaticWarningConformTest(String fileName, String body) {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5)
+ return;
+ Map compilerOptions = getCompilerOptions();
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
+ this.runConformTest(
+ new String[] {
+ fileName,
+ body
+ },
+ compilerOptions /* custom options */
+ );
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+//Can be static warning shown in the wrong places, i.e. if the type parameter is used in the signature
+public void test378674_comment0() {
+ runStaticWarningConformTest(
+ "Test.java",
+ "public class Test<T> {\n" +
+ "\n" +
+ " @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n" +
+ " public static void main(String[] args) {\n" +
+ " new Test().method(null);\n" +
+ " }\n" +
+ "\n" +
+ " private static class SubClass<A> {\n" +
+ "\n" +
+ " }\n" +
+ "\n" +
+ " private void method(SubClass<T> s) {\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ "\n" +
+ "}\n" +
+ ""
+ );
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+public void test378674_comment1b() {
+ runStaticWarningConformTest(
+ "X.java",
+ "import java.util.Collection;\n" +
+ "class X<E>{\n" +
+ " public final <E1> Collection<E> go() { // cannot be static\n" +
+ " return null; \n" +
+ " }\n" +
+ "}\n" +
+ ""
+ );
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+//Can be static warning shown in the wrong places
+public void test378674_comment1c() {
+ runStaticWarningConformTest(
+ "X.java",
+ "import java.util.Collection;\n" +
+ "import java.util.ArrayList;\n" +
+ " class X<E>{\n" +
+ " public final <E1> Collection<?> go() { // cannot be static\n" +
+ " return new ArrayList<E>(); \n" +
+ " }\n" +
+ "}\n" +
+ ""
+ );
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+//Can be static warning shown in the wrong places
+public void test378674_comment2() {
+ runStaticWarningConformTest(
+ "X.java",
+ "public class X<T> {\n" +
+ " public final void foo() {\n" +
+ " java.util.List<T> k;\n" +
+ " }\n" +
+ "}\n" +
+ ""
+ );
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+public void test378674_comment3() {
+ runStaticWarningConformTest(
+ "Test.java",
+ "public class Test {\n" +
+ " //false positive of method can be declared static\n" +
+ " void bar() {\n" +
+ " foo(Test.this);\n" +
+ " }\n" +
+ "\n" +
+ " private static void foo(Test test) {\n" +
+ " System.out.println(test.getClass().getName());\n" +
+ " }\n" +
+ "}\n" +
+ ""
+ );
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+//Can be static warning shown in the wrong places
+public void test378674_comment5a() {
+ runStaticWarningConformTest(
+ "Test.java",
+ "public class Test<T> {\n" +
+ "\n" +
+ " @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n" +
+ " public static void main(String[] args) {\n" +
+ " new Test().method2(null);\n" +
+ " }\n" +
+ "\n" +
+ " private static class SubClass<A> {\n" +
+ "\n" +
+ " }\n" +
+ "\n" +
+ " private void method2(SubClass<java.util.List<T>> s) {\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ "\n" +
+ "}\n" +
+ ""
+ );
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+public void test378674_comment5b() {
+ runStaticWarningConformTest(
+ "Test.java",
+ "public class Test<T> {\n" +
+ "\n" +
+ " @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n" +
+ " public static void main(String[] args) {\n" +
+ " new Test().method();\n" +
+ " }\n" +
+ "\n" +
+ " private java.util.Collection<T> method() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "\n" +
+ "}\n" +
+ ""
+ );
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+public void test378674_comment9() {
+ runStaticWarningConformTest(
+ "Test.java",
+ "public class Test<T> {\n" +
+ "\n" +
+ " @SuppressWarnings({ \"rawtypes\" })\n" +
+ " public static void main(String[] args) {\n" +
+ " new Test().method();\n" +
+ " }\n" +
+ "\n" +
+ " private java.util.Collection<? extends T> method() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ ""
+ );
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+public void test378674_comment11() {
+ runStaticWarningConformTest(
+ "Test.java",
+ "public class Test<T> {\n" +
+ "\n" +
+ " @SuppressWarnings({ \"rawtypes\" })\n" +
+ " public static void main(String[] args) {\n" +
+ " new Test().method1();\n" +
+ " new Test().method2();\n" +
+ " }\n" +
+ "\n" +
+ " private <TT extends T> TT method1() { \n" +
+ " return null;\n" +
+ " }\n" +
+ "\n" +
+ " private <TT extends Object & Comparable<? super T>> TT method2() { \n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ ""
+ );
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+public void test378674_comment21a() {
+ runStaticWarningConformTest(
+ "X.java",
+ "public class X<P extends Exception> {\n" +
+ " final <T> void foo(T x) throws P {\n" +
+ " }\n" +
+ "}\n" +
+ ""
+ );
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+public void test378674_comment21b() {
+ runStaticWarningConformTest(
+ "X.java",
+ "public class X<P extends Exception> {\n" +
+ " final <T> void foo(T x) {\n" +
+ " Object o = (P) null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+public void test378674_comment21c() {
+ runStaticWarningConformTest(
+ "X.java",
+ "public class X<P extends Exception> {\n" +
+ " final <T> void foo(T x) {\n" +
+ " new Outer().new Inner<P>();\n" +
+ " }\n" +
+ "}\n" +
+ "class Outer {\n" +
+ " class Inner<Q> {}\n" +
+ "}\n"
+ );
+}//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674
+public void test378674_comment21d() {
+ runStaticWarningConformTest(
+ "X.java",
+ "public class X<P extends Exception> {\n" +
+ " final <T> void foo(T x) {\n" +
+ " class Local {\n" +
+ " P p;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ );
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java
index a2d81a45f..7abac6172 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -7,7 +7,9 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
+ * Stephan Herrmann - Contributions for
+ * bug 185682 - Increment/decrement operators mark local variables as read
+ * bug 401271 - StackOverflowError when searching for a methods references
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -18,7 +20,8 @@ public class StaticImportTest extends AbstractComparableTest {
// Static initializer to specify tests subset using TESTS_* static variables
// All specified tests which do not belong to the class are skipped...
static {
-// TESTS_NAMES = new String[] { "test036" };
+// TESTS_NAMES = new String[] { "testBug401271" };
+// TESTS_NAMES = new String[] { "test085c" };
// TESTS_NUMBERS = new int[] { 80 };
// TESTS_RANGE = new int[] { 75, -1 };
}
@@ -3077,5 +3080,34 @@ public class StaticImportTest extends AbstractComparableTest {
"Bar\'s field B");
}
+ // https://bugs.eclipse.org/401271 - StackOverflowError when searching for a methods references
+ public void testBug401271() {
+ runNegativeTest(
+ new String[] {
+ "a/b/c/a.java",
+ "package a.b.c;\n" +
+ "public class a {}\n",
+ "a/b/c/C.java",
+ "package a.b.c;\n" +
+ "public class C {\n" +
+ " public static final int a = 3;\n" +
+ "}\n",
+ "x/y/R.java",
+ "package x.y;\n" +
+ "import static a.b.c.C.a;\n" +
+ "//import a.b.c.a;\n" +
+ "\n" +
+ "public class R { \n" +
+ " a b; \n" +
+ " char h = a; \n" +
+ "}"
+ },
+ "----------\n" +
+ "1. ERROR in x\\y\\R.java (at line 6)\n" +
+ " a b; \n" +
+ " ^\n" +
+ "a cannot be resolved to a type\n" +
+ "----------\n");
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/pom.xml b/org.eclipse.jdt.core.tests.model/pom.xml
index 1415479f4..ee39c3fa5 100644
--- a/org.eclipse.jdt.core.tests.model/pom.xml
+++ b/org.eclipse.jdt.core.tests.model/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2012 Eclipse Foundation.
+ Copyright (c) 2012, 2013 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
@@ -18,7 +18,7 @@
<groupId>eclipse.jdt.core</groupId>
<version>3.8.0-SNAPSHOT</version>
</parent>
- <groupId>eclipse.jdt.core</groupId>
+ <groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core.tests.model</artifactId>
<version>3.8.2-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
index e67367d99..9c28c599d 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -66,6 +66,13 @@ public class ASTConverter15Test extends ConverterTestSetup {
this.workingCopy = null;
}
}
+ private void assertArrayEquals(int[] expectedAnnotationsSize,
+ int[] actualAnnotationsSize) {
+ assertEquals("wrong array size", expectedAnnotationsSize.length, actualAnnotationsSize.length);
+ for (int i = 0, max = expectedAnnotationsSize.length; i < max; i++) {
+ assertEquals("Wrong element at " + i, expectedAnnotationsSize[i], actualAnnotationsSize[i]);
+ }
+ }
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=234609 BindingKey#toSignature() fails with key from createWilcardTypeBindingKey(..)
public void test234609() throws JavaModelException {
@@ -11452,5 +11459,72 @@ public class ASTConverter15Test extends ConverterTestSetup {
deleteProject(jp);
}
}
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=376440
+ public void testBug376440() throws JavaModelException {
+ String str =
+ "package p;\n" +
+ "class X extends p.Z<String>{}\n" +
+ "class X extends p.Z<String> {}\n" +
+ "class Z<T> {}\n";
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(str,this.workingCopy, false);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Invaid no of types", 3, compilationUnit.types().size());
+ TypeDeclaration typeDecl = (TypeDeclaration) compilationUnit.types().get(0);
+ Type type = typeDecl.getSuperclassType();
+ ITypeBinding bindingFromAST = type.resolveBinding();
+ assertNotNull("Binding should not be null", bindingFromAST);
+ typeDecl = (TypeDeclaration) compilationUnit.types().get(1);
+ type = typeDecl.getSuperclassType();
+ try {
+ bindingFromAST = type.resolveBinding();
+ } catch(Exception e) {
+ fail("Should not throw exception, should just return null binding");
+ }
+ assertNull("Binding should be null", bindingFromAST);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=398520
+ */
+ public void testBug398520() throws CoreException {
+ String jarLocation = getWorkspacePath()+"Converter15/bins/bug398520.jar";
+ IJavaProject jp = createJavaProject("Bug398520", new String[]{"src"}, new String[]{"CONVERTER_JCL15_LIB", jarLocation}, "bin", "1.5");
+ try {
+ this.workingCopy = getWorkingCopy("/Bug398520/src/testBug398520/C.java", true/*resolve*/);
+ String contents =
+ "package testBug398520;\n" +
+ "import pack.*;\n" +
+ "public class C {\n" +
+ " public Object foo() {\n" +
+ " return new T<String, String>().new C().new Iter(\"\", 0, null);\n" +
+ " }\n" +
+ "}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ ASTNode astNode = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, astNode.getNodeType());
+ ReturnStatement statement = (ReturnStatement) astNode;
+ Expression expression = statement.getExpression();
+ ClassInstanceCreation creation = (ClassInstanceCreation) expression;
+ IMethodBinding methodBinding = creation.resolveConstructorBinding();
+ int[] expectedAnnotationsSize = new int[] { 1, 0, 1};
+ int[] actualAnnotationsSize = new int[] {
+ methodBinding.getParameterAnnotations(0).length,
+ methodBinding.getParameterAnnotations(1).length,
+ methodBinding.getParameterAnnotations(2).length
+ };
+ assertArrayEquals(expectedAnnotationsSize, actualAnnotationsSize);
+ } finally {
+ deleteProject(jp);
+ }
+ }
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java
index f131b4012..59906000a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -10,7 +10,8 @@
*******************************************************************************/
package org.eclipse.jdt.core.tests.dom;
-import java.io.*;
+import java.io.File;
+import java.io.IOException;
import java.lang.reflect.Method;
import java.text.NumberFormat;
import java.util.ArrayList;
@@ -27,7 +28,44 @@ import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.IProblem;
-import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTMatcher;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.ArrayType;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.Comment;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
+import org.eclipse.jdt.core.dom.EnumDeclaration;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.ExpressionStatement;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.IPackageBinding;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.IfStatement;
+import org.eclipse.jdt.core.dom.Javadoc;
+import org.eclipse.jdt.core.dom.MemberRef;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.MethodRef;
+import org.eclipse.jdt.core.dom.MethodRefParameter;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.PackageDeclaration;
+import org.eclipse.jdt.core.dom.PrimitiveType;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.ReturnStatement;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SimpleType;
+import org.eclipse.jdt.core.dom.Statement;
+import org.eclipse.jdt.core.dom.TagElement;
+import org.eclipse.jdt.core.dom.TextElement;
+import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.TypeDeclarationStatement;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
/**
@@ -109,7 +147,17 @@ public class ASTConverterJavadocTest extends ConverterTestSetup {
* @param name
*/
public ASTConverterJavadocTest(String name) {
- this(name, JavaCore.ENABLED, UNIX_SUPPORT);
+ this(name.substring(0, name.indexOf(" - ")),
+ name.substring(name.indexOf(" - Doc ") + 7, name.lastIndexOf("abled") + 5),
+ name.indexOf(" - Unix") != -1 ? "true" : "false");
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#getName()
+ */
+ public String getName() {
+ String strUnix = this.unix ? " - Unix" : "";
+ return super.getName()+" - Doc "+this.docCommentSupport+strUnix;
}
public static Test suite() {
@@ -175,13 +223,6 @@ public class ASTConverterJavadocTest extends ConverterTestSetup {
}
}
/* (non-Javadoc)
- * @see junit.framework.TestCase#getName()
- */
- public String getName() {
- String strUnix = this.unix ? " - Unix" : "";
- return "Doc "+this.docCommentSupport+strUnix+" - "+super.getName();
- }
- /* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
@@ -3299,4 +3340,33 @@ public class ASTConverterJavadocTest extends ConverterTestSetup {
ICompilationUnit unit = getCompilationUnit("Converter" , "src", "javadoc.testBug336821", "Try.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
verifyComments(unit);
}
+
+ public void testBug347100() throws Exception {
+ ICompilationUnit unit = getCompilationUnit("Converter" , "src", "javadoc.testBug347100", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit compilUnit = verifyComments(unit);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ Javadoc comment = (Javadoc) compilUnit.getCommentList().get(0);
+ List tags = comment.tags();
+ assertEquals(4, tags.size());
+
+ List mainTags = ((TagElement) tags.get(0)).fragments();
+ assertEquals(8, mainTags.size());
+
+ TagElement link1 = (TagElement) mainTags.get(1);
+ assertEquals(TagElement.TAG_LINK, link1.getTagName());
+ SimpleName javadocRef = (SimpleName) link1.fragments().get(0);
+ assertTrue(javadocRef.resolveBinding() instanceof IPackageBinding);
+ link1.subtreeMatch(new ASTMatcher(true), tags.get(1));
+
+ TagElement link2 = (TagElement) mainTags.get(4);
+ assertEquals(TagElement.TAG_LINK, link2.getTagName());
+ TextElement stringRef = (TextElement) link2.fragments().get(0);
+ assertEquals(" \"Hello World\"", stringRef.getText());
+ link2.subtreeMatch(new ASTMatcher(true), tags.get(2));
+
+ TagElement link3 = (TagElement) mainTags.get(7);
+ assertEquals(TagElement.TAG_LINK, link3.getTagName());
+ link3.subtreeMatch(new ASTMatcher(true), tags.get(3));
+ }
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java
index 0a5987276..206bb7123 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -70,6 +70,7 @@ public abstract class ConverterTestSetup extends AbstractASTTests {
this.deleteProject("Converter15"); //$NON-NLS-1$
this.deleteProject("Converter16"); //$NON-NLS-1$
this.deleteProject("Converter17"); //$NON-NLS-1$
+ PROJECT_SETUP = false;
} else {
TEST_SUITES.remove(getClass());
if (TEST_SUITES.size() == 0) {
@@ -77,6 +78,7 @@ public abstract class ConverterTestSetup extends AbstractASTTests {
this.deleteProject("Converter15"); //$NON-NLS-1$
this.deleteProject("Converter16"); //$NON-NLS-1$
this.deleteProject("Converter17"); //$NON-NLS-1$
+ PROJECT_SETUP = false;
}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
index 916f3174f..7ab7d1774 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -1179,6 +1179,27 @@ public abstract class AbstractJavaModelTests extends SuiteOfTestCases {
}
}
}
+ protected IFile createFile(String path, InputStream content) throws CoreException {
+ IFile file = getFile(path);
+ file.create(content, true, null);
+ try {
+ content.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return file;
+ }
+
+ protected IFile createFile(String path, byte[] content) throws CoreException {
+ return createFile(path, new ByteArrayInputStream(content));
+ }
+
+ protected IFile createFile(String path, String content) throws CoreException {
+ return createFile(path, content.getBytes());
+ }
+ protected IFolder createFolder(String path) throws CoreException {
+ return createFolder(new Path(path));
+ }
protected IFolder createFolder(IPath path) throws CoreException {
final IFolder folder = getWorkspaceRoot().getFolder(path);
getWorkspace().run(new IWorkspaceRunnable() {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
index fdadfe7d8..d5d2351f1 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.jdt.core.tests.model;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
@@ -369,7 +370,14 @@ public class AttachedJavadocTests extends ModifyingResourceTests {
assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
IClassFile classFile = packageFragment.getClassFile("W.class"); //$NON-NLS-1$
assertNotNull(classFile);
- String javadoc = classFile.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
+ String javadoc = null;
+ try {
+ javadoc = classFile.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
+ } catch(JavaModelException jme) {
+ if (!(jme.getCause() instanceof FileNotFoundException)) {
+ fail("Can only throw a FileNotFoundException");
+ }
+ }
assertNull("Should not have a javadoc", javadoc); //$NON-NLS-1$
}
@@ -1159,7 +1167,9 @@ public class AttachedJavadocTests extends ModifyingResourceTests {
String javadoc = packageFragment.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
assertNull("Javadoc should be null", javadoc); //$NON-NLS-1$
} catch(JavaModelException jme) {
- fail("Should not throw Java Model Exception");
+ if (!(jme.getCause() instanceof FileNotFoundException)) {
+ fail("Should not throw Java Model Exception");
+ }
}
}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
index ef8058820..a050ffe03 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -4388,7 +4388,7 @@ public void testCompletionAfterSupercall1() throws JavaModelException {
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
assertResults(
- "foo[METHOD_REF]{foo(), LCompletionAfterSupercall1_2;, ()V, foo, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_NON_STATIC+ R_NON_RESTRICTED) + "}",
+ "foo[METHOD_REF]{foo(), LCompletionAfterSupercall1_2;, ()V, foo, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_NON_STATIC+ R_NON_RESTRICTED + R_EXACT_NAME + R_METHOD_OVERIDE) + "}",
requestor.getResults());
}
public void testCompletionAfterSwitch() throws JavaModelException {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests2.java
index c2b786928..96c191375 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests2.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests2.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -6047,4 +6047,57 @@ public void testBug397070() throws JavaModelException {
fail("Invalid completion context");
}
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=392581
+public void testBug392581() throws CoreException {
+ try {
+ // Create project and jar
+ IJavaProject p = createJavaProject("P", new String[] {"src"}, new String[]{"JCL_LIB"}, "bin");
+ createFolder("/P/src/p");
+ refresh(p);
+ // Create working copy
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/P/src/p/B.java",
+ "class A {\n" +
+ " protected String foo1(){\n" +
+ " return \"From A\";\n" +
+ " }\n" +
+ "}\n" +
+ "public class B extends A {\n" +
+ " @Override\n" +
+ " protected String foo1() {\n" +
+ " super. \n" +
+ " }\n" +
+ "}");
+
+ // do completion
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.setRequireExtendedContext(true);
+ requestor.setComputeVisibleElements(true);
+ requestor.allowAllRequiredProposals();
+ NullProgressMonitor monitor = new NullProgressMonitor();
+
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "super.";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
+
+ assertResults(
+ "clone[METHOD_REF]{clone(), Ljava.lang.Object;, ()Ljava.lang.Object;, clone, null, "+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED) + "}\n"
+ + "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), "+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED) + "}\n"
+ + "finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, finalize, null, "+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED) + "}\n"
+ + "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class;, getClass, null, "+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED) + "}\n"
+ + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, "+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED) + "}\n"
+ + "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, notify, null, "+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED) + "}\n"
+ + "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, notifyAll, null, "+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED) + "}\n"
+ + "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, "+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED) + "}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, wait, null, "+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED) + "}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, wait, (millis), "+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED) + "}\n"
+ + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, wait, (millis, nanos), "+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED) + "}\n"
+ + "foo1[METHOD_REF]{foo1(), Lp.A;, ()Ljava.lang.String;, foo1, null, "+ (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED + R_EXACT_NAME + R_METHOD_OVERIDE) + "}",
+ requestor.getResults());
+ } finally {
+ deleteProject("P");
+ }
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SelectionJavadocModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SelectionJavadocModelTests.java
index 7cb2752d9..f7ccb14ba 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SelectionJavadocModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SelectionJavadocModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -1537,4 +1537,75 @@ public class SelectionJavadocModelTests extends AbstractJavaModelTests {
elements
);
}
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=400767
+ public void testBug400767() throws Exception {
+ String content = "package test;\n"
+ + "import b400767.ETest;\n"
+ + "public class Bug {\n"
+ + " Bug() {\n"
+ + " doSomethingUsingOtherPackage();\n"
+ + " }\n"
+ + " public void addComponentListener(ComponentListener listener) {}\n"
+ + " private void doSomethingUsingOtherPackage() {\n"
+ + " for (ETest val : ETest.values()) {\n"
+ + " System.out.println(val.name());\n"
+ + " }\n"
+ + " Bug bug = new Bug();\n"
+ + " bug.addComponentListener(new ComponentAdapter() {\n"
+ + " /**\n"
+ + " * @see ComponentAdapter#componentShown(ComponentEvent)\n"
+ + " */\n"
+ + " @Override\n"
+ + " public void componentShown(ComponentEvent e) {\n"
+ + " super.componentShown(e);\n"
+ + " }\n"
+ + " });\n"
+ + " }\n"
+ + "}\n"
+ + "interface ComponentListener {\n"
+ + " public void componentShown(ComponentEvent e);\n"
+ + "}\n"
+ + "class ComponentAdapter implements ComponentListener {\n"
+ + " public void componentShown(ComponentEvent e) { }\n"
+ + "}\n"
+ + "class ComponentEvent {}";
+ this.wcOwner = new WorkingCopyOwner() {};
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[2] = getWorkingCopy("/Tests/test/ETest.java", content);
+ content = "/**\n "
+ + "* This package is used by another package and will cause an error.\n"
+ + " */\n"
+ + "package b400767;";
+ // package-info is physically required at some point. Just put it to move forward.
+ createFolder("/Tests/b400767");
+ createFile("/Tests/b400767/package-info.java", content);
+ this.workingCopies[0] = getWorkingCopy("/Tests/b400767/package-info.java", content);
+ content = "package b400767;\n"
+ + "public enum ETest {\n"
+ + " VAL1, VAL2, VAL3;\n"
+ + "}";
+ this.workingCopies[1] = getWorkingCopy("/Tests/b400767/ETest.java", content);
+ final IJavaElement[] selection = new IJavaElement[1];
+ final ICompilationUnit[] copy = this.workingCopies;
+ Thread t = new Thread(new Runnable() {
+ public void run() {
+ try {
+ selection[0] = selectMethod(copy[2], "componentShown");
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ fail("Shouldn't be an exception");
+ }
+ }
+ });
+ t.start();
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ }
+ if (t.isAlive()) {
+ fail("Thread shouldn't still be running");
+ }
+ assertElementEquals("Should return a valid element",
+ "componentShown(ComponentEvent) [in ComponentAdapter [in [Working copy] ETest.java [in test [in <project root> [in Tests]]]]]", selection[0]);
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyNotificationTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyNotificationTests.java
index cd9e0d454..88182d0c5 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyNotificationTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyNotificationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -102,7 +102,7 @@ private void reset() {
protected void setUp() throws Exception {
super.setUp();
reset();
- this.setUpJavaProject("TypeHierarchyNotification");
+ this.setUpJavaProject("TypeHierarchyNotification", "1.5");
}
static {
// TESTS_NAMES= new String[] { "testAddExtendsSourceType3" };
@@ -258,6 +258,39 @@ public void testAddCompilationUnit3() throws CoreException {
}
}
/**
+ * When a CU is added the type hierarchy should change
+ * only if one of the types of the CU is part of the
+ * type hierarchy. Tests parameterized supertype, see https://bugs.eclipse.org/401726
+ */
+public void testAddCompilationUnit4() throws CoreException {
+ IJavaProject javaProject = getJavaProject("TypeHierarchyNotification");
+ IType collection= javaProject.findType("java.util.Collection");
+ ITypeHierarchy h = collection.newTypeHierarchy(javaProject, null);
+ h.addTypeHierarchyChangedListener(this);
+
+ // a cu with a top level type which is part of the hierarchy
+ IPackageFragment pkg = getPackageFragment("TypeHierarchyNotification", "src", "p");
+ ICompilationUnit newCU2 = pkg.createCompilationUnit(
+ "Z2.java",
+ "package p;\n" +
+ "\n" +
+ "public abstract class Z2 extends java.util.Collection<java.lang.String> {\n" +
+ "}\n",
+ false,
+ null);
+ try {
+ assertCreation(newCU2);
+ assertOneChange(h);
+ h.refresh(null);
+ IType[] subtypes = h.getSubtypes(collection);
+ assertTrue("Should be one subtype of Collection", subtypes.length == 1);
+ assertEquals("Subtype of Collection should be p.Z2", newCU2.getType("Z2"), subtypes[0]);
+ } finally {
+ // cleanup
+ h.removeTypeHierarchyChangedListener(this);
+ }
+}
+/**
* When a CU is added, if the type hierarchy doesn't have a focus, it should change
* only if one of the types of the CU is part of the region.
*/
@@ -330,7 +363,7 @@ public void testAddCompilationUnitInRegion() throws CoreException, IOException {
assertCreation(newCU3);
assertOneChange(h);
h.refresh(null);
- IType throwableClass = getClassFile("TypeHierarchyNotification", getExternalJCLPathString(), "java.lang", "Throwable.class").getType();
+ IType throwableClass = getClassFile("TypeHierarchyNotification", getExternalJCLPathString("1.5"), "java.lang", "Throwable.class").getType();
assertEquals("Superclass of Z3 should be java.lang.Throwable", throwableClass, h.getSuperclass(newCU3.getType("Z3")));
} finally {
// cleanup
@@ -1394,11 +1427,12 @@ public void testBug316654_a() throws CoreException {
public void testBug316654_b() throws CoreException {
IJavaProject project = getJavaProject("TypeHierarchyNotification");
refreshExternalArchives(project);
- File jarFile = new File(getExternalJCLPathString());
+ String externalJCLPathString = getExternalJCLPathString("1.5");
+ File jarFile = new File(externalJCLPathString);
long oldTimestamp = jarFile.lastModified();
assertTrue("File does not exist", jarFile.exists());
- IType throwableClass = getClassFile("TypeHierarchyNotification", getExternalJCLPathString(), "java.lang", "Throwable.class").getType();
+ IType throwableClass = getClassFile("TypeHierarchyNotification", externalJCLPathString, "java.lang", "Throwable.class").getType();
ITypeHierarchy h = throwableClass.newTypeHierarchy(project, null);
h.addTypeHierarchyChangedListener(this);
reset();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java
index a0f688e06..b24bf98ad 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Stephan Herrmann - contribution for Bug 300576 - NPE Computing type hierarchy when compliance doesn't match libraries
+ * Jesper S Moller - contributions for bug 393192 - Incomplete type hierarchy with > 10 annotations
*******************************************************************************/
package org.eclipse.jdt.core.tests.model;
@@ -15,6 +16,8 @@ import java.io.File;
import java.io.IOException;
import java.util.HashMap;
+import junit.framework.Test;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
@@ -22,14 +25,23 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
-
-import org.eclipse.jdt.core.*;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IRegion;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.tests.model.SearchTests.WaitingJob;
import org.eclipse.jdt.core.tests.model.Semaphore.TimeOutException;
import org.eclipse.jdt.core.tests.util.Util;
-import junit.framework.Test;
-
public class TypeHierarchyTests extends ModifyingResourceTests {
/**
* A placeholder for a type hierarchy used in some test cases.
@@ -2604,4 +2616,91 @@ public void testBug300576b() throws CoreException {
deleteProject(prj);
}
}
-}
+//Bug 393192 -- Incomplete type hierarchy with > 10 annotations
+public void testBug393192() throws CoreException {
+ IJavaProject prj = null;
+ try {
+ prj = createJavaProject("Bug393192", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin", "1.5");
+ createFolder("/Bug393192/src/pullup");
+ createFile("/Bug393192/src/pullup/A.java",
+ "package pullup;\n" +
+ "\n" +
+ "class A {\n" +
+ " @Deprecated\n" +
+ " void m0() {\n" +
+ " }\n" +
+ "\n" +
+ " @Deprecated\n" +
+ " void m1() {\n" +
+ " }\n" +
+ "\n" +
+ " @Deprecated\n" +
+ " void m2() {\n" +
+ " }\n" +
+ "\n" +
+ " @Deprecated\n" +
+ " void m3() {\n" +
+ " }\n" +
+ "\n" +
+ " @Deprecated\n" +
+ " void m4() {\n" +
+ " }\n" +
+ "\n" +
+ " @Deprecated\n" +
+ " void m5() {\n" +
+ " }\n" +
+ "\n" +
+ " @Deprecated\n" +
+ " void m6() {\n" +
+ " }\n" +
+ "\n" +
+ " @Deprecated\n" +
+ " void m7() {\n" +
+ " }\n" +
+ "\n" +
+ " @Deprecated\n" +
+ " void m8() {\n" +
+ " }\n" +
+ "\n" +
+ " @Deprecated\n" +
+ " void m9() {\n" +
+ " }\n" +
+ "\n" +
+ " /**\n" +
+ " * @param\n" +
+ " */\n" +
+ " @Deprecated\n" +
+ " void m10() {\n" +
+ " }\n" +
+ "}\n" +
+ "\n");
+ createFile("/Bug393192/src/pullup/package-info.java",
+ "package pullup;\n" +
+ "\n");
+ createFile("/Bug393192/src/pullup/PullUpBug.java",
+ "package pullup;\n" +
+ "\n" +
+ "class PullUpBug extends A {\n" +
+ "\n" +
+ " void mb() {\n" +
+ " pullUp();\n" +
+ " }\n" +
+ "\n" +
+ " // INVOKE Pull Up REFACTORING ON \"pullUp\", or type Hierarchy on A\n" +
+ " private void pullUp() {\n" +
+ " }\n" +
+ "}\n");
+ IType a = getCompilationUnit("Bug393192", "src", "pullup", "A.java").getType("A");
+ ITypeHierarchy hierarchy = a.newTypeHierarchy(new NullProgressMonitor());
+ assertHierarchyEquals(
+ "Focus: A [in A.java [in pullup [in src [in Bug393192]]]]\n" +
+ "Super types:\n" +
+ " Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" +
+ "Sub types:\n" +
+ " PullUpBug [in PullUpBug.java [in pullup [in src [in Bug393192]]]]\n",
+ hierarchy);
+ } finally {
+ if (prj != null)
+ deleteProject(prj);
+ }
+}} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Converter/src/javadoc/testBug347100/X.java b/org.eclipse.jdt.core.tests.model/workspace/Converter/src/javadoc/testBug347100/X.java
new file mode 100644
index 000000000..33df57656
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Converter/src/javadoc/testBug347100/X.java
@@ -0,0 +1,12 @@
+package javadoc.testBug347100;
+/**
+ * Link to {@link javadoc},<br>
+ * link to {@link "Hello World"},<br>
+ * and {@link <a href="../package-summary.html">package documentation</a>}
+ *
+ * @see javadoc
+ * @see "Hello World"
+ * @see <a href="../package-summary.html">package documentation</a>
+ */
+public class X {
+}
diff --git a/org.eclipse.jdt.core/.settings/.api_filters b/org.eclipse.jdt.core/.settings/.api_filters
new file mode 100644
index 000000000..fdfa23c39
--- /dev/null
+++ b/org.eclipse.jdt.core/.settings/.api_filters
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?><component id="org.eclipse.jdt.core" version="2">
+ <resource path="model/org/eclipse/jdt/core/IAccessRule.java" type="org.eclipse.jdt.core.IAccessRule">
+ <filter id="403853384">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.core.IAccessRule"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="model/org/eclipse/jdt/core/IAnnotatable.java" type="org.eclipse.jdt.core.IAnnotatable">
+ <filter id="403853384">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.core.IAnnotatable"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="model/org/eclipse/jdt/core/IAnnotation.java" type="org.eclipse.jdt.core.IAnnotation">
+ <filter id="403853384">
+ <message_arguments>
+ <message_argument value="org.eclipse.jdt.core.IAnnotation"/>
+ </message_arguments>
+ </filter>
+ </resource>
+</component> \ No newline at end of file
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
index 57e8a0e12..b32eec756 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -4400,6 +4400,27 @@ public final class CompletionEngine
return 0;
}
+ private int computeRelevanceForSuper(MethodBinding method, Scope scope, InvocationSite site) {
+ if (site instanceof CompletionOnMemberAccess) {
+ CompletionOnMemberAccess access = (CompletionOnMemberAccess) site;
+ if (access.isSuperAccess() && this.parser.assistNodeParent == null) {
+ ReferenceContext referenceContext = scope.referenceContext();
+ if (referenceContext instanceof AbstractMethodDeclaration) {
+ MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding;
+ if (binding != null) {
+ if (CharOperation.equals(binding.selector, method.selector)) {
+ if (binding.areParameterErasuresEqual(method)) {
+ return R_EXACT_NAME + R_METHOD_OVERIDE;
+ }
+ return R_EXACT_NAME;
+ }
+ }
+ }
+ }
+ }
+ return 0;
+ }
+
private long computeTargetedElement(CompletionOnAnnotationOfType fakeNode) {
ASTNode annotatedElement = fakeNode.potentialAnnotatedNode;
@@ -9121,7 +9142,7 @@ public final class CompletionEngine
if (missingElements != null) {
relevance += computeRelevanceForMissingElements(missingElementsHaveProblems);
}
-
+ relevance += computeRelevanceForSuper(method, scope, invocationSite);
this.noProposal = false;
if (castedReceiver == null) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
index d59991260..87b8af0f1 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -163,6 +163,10 @@
* ConflictingNullAnnotations
* ConflictingInheritedNullAnnotations
* UnsafeElementTypeConversion
+ * PotentialNullUnboxing
+ * NullUnboxing
+ * NullExpressionReference
+ * PotentialNullExpressionReference
*******************************************************************************/
package org.eclipse.jdt.core.compiler;
@@ -905,6 +909,10 @@ void setSourceStart(int sourceStart);
int RedundantNullCheckOnNonNullLocalVariable = Internal + 457;
/** @since 3.3 */
int NonNullLocalVariableComparisonYieldsFalse = Internal + 458;
+ /** @since 3.9 */
+ int PotentialNullUnboxing = Internal + 459;
+ /** @since 3.9 */
+ int NullUnboxing = Internal + 461;
// block
/** @since 3.0 */
@@ -1324,6 +1332,10 @@ void setSourceStart(int sourceStart);
int NonNullExpressionComparisonYieldsFalse = Internal + 670;
/** @since 3.9 */
int RedundantNullCheckOnNonNullExpression = Internal + 671;
+ /** @since 3.9 */
+ int NullExpressionReference = Internal + 672;
+ /** @since 3.9 */
+ int PotentialNullExpressionReference = Internal + 673;
/**
* Corrupted binaries
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java
index 5fe03b0b2..1dc3594cb 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -16,6 +16,8 @@
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation.
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * bug 401017 - [compiler][null] casted reference to @Nullable field lacks a warning
+ * bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -148,9 +150,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
FlowInfo result = this.expression
.analyseCode(currentScope, flowContext, flowInfo)
.unconditionalInits();
- if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.expression.checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.expression.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
// account for pot. CCE:
flowContext.recordAbruptExit();
return result;
@@ -340,6 +340,11 @@ public static void checkNeedForArgumentCasts(BlockScope scope, int operator, int
}
}
+public boolean checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) {
+ checkNPEbyUnboxing(scope, flowContext, flowInfo);
+ return this.expression.checkNPE(scope, flowContext, flowInfo);
+}
+
private static void checkAlternateBinding(BlockScope scope, Expression receiver, TypeBinding receiverType, MethodBinding binding, Expression[] arguments, TypeBinding[] originalArgumentTypes, TypeBinding[] alternateArgumentTypes, final InvocationSite invocationSite) {
InvocationSite fakeInvocationSite = new InvocationSite(){
public TypeBinding[] genericTypeArguments() { return null; }
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java
index 1f1c38f0d..078c2c4bc 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -18,6 +18,7 @@
* bug 349326 - [1.7] new warning for missing try-with-resources
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -85,6 +86,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext,
}
this.trueInitStateIndex = currentScope.methodScope().recordInitializationStates(trueFlowInfo);
trueFlowInfo = this.valueIfTrue.analyseCode(currentScope, flowContext, trueFlowInfo);
+ this.valueIfTrue.checkNPEbyUnboxing(currentScope, flowContext, trueFlowInfo);
// may need to fetch this null status before expireNullCheckedFieldInfo():
int preComputedTrueNullStatus = -1;
@@ -106,6 +108,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext,
}
this.falseInitStateIndex = currentScope.methodScope().recordInitializationStates(falseFlowInfo);
falseFlowInfo = this.valueIfFalse.analyseCode(currentScope, flowContext, falseFlowInfo);
+ this.valueIfFalse.checkNPEbyUnboxing(currentScope, flowContext, falseFlowInfo);
flowContext.conditionalLevel--;
@@ -176,6 +179,14 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext,
return mergedInfo;
}
+ public boolean checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) {
+ if ((this.nullStatus & FlowInfo.NULL) != 0)
+ scope.problemReporter().expressionNullReference(this);
+ else if ((this.nullStatus & FlowInfo.POTENTIALLY_NULL) != 0)
+ scope.problemReporter().expressionPotentialNullReference(this);
+ return true; // all checking done
+ }
+
private void computeNullStatus(int ifTrueNullStatus, FlowInfo trueBranchInfo, FlowInfo falseBranchInfo, FlowContext flowContext) {
// given that the condition cannot be optimized to a constant
// we now merge the nullStatus from both branches:
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
index e56b23c7c..80b3e32ce 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
@@ -18,6 +18,7 @@
* bug 383690 - [compiler] location of error re uninitialized final field should be aligned
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * bug 400421 - [compiler] Null analysis for fields does not take @com.google.inject.Inject into account
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -320,10 +321,12 @@ public void analyseCode(ClassScope classScope, InitializationFlowContext initial
? (ASTNode) this.scope.referenceType().declarationOf(field.original())
: this);
} else if (field.isNonNull()) {
+ FieldDeclaration fieldDecl = this.scope.referenceType().declarationOf(field.original());
+ if (!isValueProvidedUsingAnnotation(fieldDecl))
this.scope.problemReporter().uninitializedNonNullField(
field,
((this.bits & ASTNode.IsDefaultConstructor) != 0)
- ? (ASTNode) this.scope.referenceType().declarationOf(field.original())
+ ? (ASTNode) fieldDecl
: this);
}
}
@@ -339,6 +342,29 @@ public void analyseCode(ClassScope classScope, InitializationFlowContext initial
}
}
+boolean isValueProvidedUsingAnnotation(FieldDeclaration fieldDecl) {
+ // a member field annotated with @Inject is considered to be initialized by the injector
+ if (fieldDecl.annotations != null) {
+ int length = fieldDecl.annotations.length;
+ for (int i = 0; i < length; i++) {
+ Annotation annotation = fieldDecl.annotations[i];
+ if (annotation.resolvedType.id == TypeIds.T_JavaxInjectInject) {
+ return true; // no concept of "optional"
+ } else if (annotation.resolvedType.id == TypeIds.T_ComGoogleInjectInject) {
+ MemberValuePair[] memberValuePairs = annotation.memberValuePairs();
+ if (memberValuePairs == Annotation.NoValuePairs)
+ return true;
+ for (int j = 0; j < memberValuePairs.length; j++) {
+ // if "optional=false" is specified, don't rely on initialization by the injector:
+ if (CharOperation.equals(memberValuePairs[j].name, TypeConstants.OPTIONAL))
+ return memberValuePairs[j].value instanceof FalseLiteral;
+ }
+ }
+ }
+ }
+ return false;
+}
+
/**
* Bytecode generation for a constructor
*
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java
index d3c33036f..ad9a6a8d5 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -11,6 +11,7 @@
* bug 186342 - [compiler][null] Using annotations for null checking
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * bug 382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -46,6 +47,7 @@ public class EqualExpression extends BinaryExpression {
rightNonNullChecked = scope.problemReporter().expressionNonNullComparison(this.right, checkEquality);
}
+ boolean contextualCheckEquality = checkEquality ^ ((flowContext.tagBits & FlowContext.INSIDE_NEGATIVE_ASSERT) != 0);
// perform flowInfo-based checks for variables and record info for syntactic null analysis for fields:
if (!leftNonNullChecked) {
LocalVariableBinding local = this.left.localVariableBinding();
@@ -54,7 +56,8 @@ public class EqualExpression extends BinaryExpression {
checkVariableComparison(scope, flowContext, flowInfo, initsWhenTrue, initsWhenFalse, local, rightStatus, this.left);
}
} else if (this.left instanceof Reference
- && ((!checkEquality && rightStatus == FlowInfo.NULL) || (checkEquality && rightStatus == FlowInfo.NON_NULL))
+ && ((!contextualCheckEquality && rightStatus == FlowInfo.NULL)
+ || (contextualCheckEquality && rightStatus == FlowInfo.NON_NULL))
&& scope.compilerOptions().enableSyntacticNullAnalysisForFields)
{
FieldBinding field = ((Reference)this.left).lastFieldBinding();
@@ -70,7 +73,8 @@ public class EqualExpression extends BinaryExpression {
checkVariableComparison(scope, flowContext, flowInfo, initsWhenTrue, initsWhenFalse, local, leftStatus, this.right);
}
} else if (this.right instanceof Reference
- && ((!checkEquality && leftStatus == FlowInfo.NULL) || (checkEquality && leftStatus == FlowInfo.NON_NULL))
+ && ((!contextualCheckEquality && leftStatus == FlowInfo.NULL)
+ || (contextualCheckEquality && leftStatus == FlowInfo.NON_NULL))
&& scope.compilerOptions().enableSyntacticNullAnalysisForFields)
{
FieldBinding field = ((Reference)this.right).lastFieldBinding();
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 25b31e126..957d91891 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
@@ -15,6 +15,7 @@
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -743,6 +744,17 @@ public boolean checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flow
return false; // not checked
}
+/** If this expression requires unboxing check if that operation can throw NPE. */
+protected void checkNPEbyUnboxing(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) {
+ if ((this.implicitConversion & UNBOXING) != 0) {
+ int status = nullStatus(flowInfo, flowContext);
+ if ((status & FlowInfo.NULL) != 0)
+ scope.problemReporter().nullUnboxing(this, this.resolvedType);
+ else if ((status & FlowInfo.POTENTIALLY_NULL) != 0)
+ scope.problemReporter().potentialNullUnboxing(this, this.resolvedType);
+ }
+}
+
public boolean checkUnsafeCast(Scope scope, TypeBinding castType, TypeBinding expressionType, TypeBinding match, boolean isNarrowing) {
if (match == castType) {
if (!isNarrowing) tagAsUnnecessaryCast(scope, castType);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java
index dac84ffdf..3dc5fc959 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -13,6 +13,7 @@
* Stephan Herrmann - Contribution for
* bug 395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation.
* bug 331649 - [compiler][null] consider null annotations for fields
+ * bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -124,6 +125,7 @@ public FlowInfo analyseCode(MethodScope initializationScope, FlowContext flowCon
initializationScope.problemReporter().nullityMismatch(this.initialization, this.initialization.resolvedType, this.binding.type, nullStatus, annotationName);
}
}
+ this.initialization.checkNPEbyUnboxing(initializationScope, flowContext, flowInfo);
}
return flowInfo;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java
index 506a1a1ba..0b3660f9c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -14,6 +14,8 @@
* bug 185682 - Increment/decrement operators mark local variables as read
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * Jesper S Moller - Contributions for
+ * Bug 378674 - "The method can be declared as static" is wrong
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -195,12 +197,6 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
if (this.receiver.isThis()) {
currentScope.resetDeclaringClassMethodStaticFlag(this.binding.declaringClass);
}
- } else if (this.receiver.isThis()) {
- if ((this.receiver.bits & ASTNode.IsImplicitThis) == 0) {
- // explicit this receiver, not allowed in static context
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682
- currentScope.resetEnclosingMethodStaticFlag();
- }
}
if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java
index cb28d425f..acfc3c5ee 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -14,6 +14,8 @@
* bug 365859 - [compiler][null] distinguish warnings based on flow analysis vs. null annotations
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 393719 - [compiler] inconsistent warnings on iteration variables
+ * Jesper S Moller - Contribution for
+ * bug 401853 - Eclipse Java compiler creates invalid bytecode (java.lang.VerifyError)
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -36,6 +38,7 @@ import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
+import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
import org.eclipse.objectteams.otdt.core.compiler.IOTConstants;
import org.eclipse.objectteams.otdt.internal.core.compiler.control.Config;
import org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator;
@@ -331,7 +334,15 @@ public class ForeachStatement extends Statement {
}
}
if (this.elementVariable.binding.resolvedPosition == -1) {
- codeStream.pop();
+ switch (this.elementVariable.binding.type.id) {
+ case TypeIds.T_long :
+ case TypeIds.T_double :
+ codeStream.pop2();
+ break;
+ default:
+ codeStream.pop();
+ break;
+ }
} else {
codeStream.store(this.elementVariable.binding, false);
codeStream.addVisibleLocalVariable(this.elementVariable.binding);
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 b21f46a1f..22ef5bca4 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -23,6 +23,9 @@
* bug 394768 - [compiler][resource] Incorrect resource leak warning when creating stream in conditional
* bug 395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation.
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
+ * Jesper S Moller - Contributions for
+ * Bug 378674 - "The method can be declared as static" is wrong
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -133,9 +136,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
if (this.initialization == null) {
return flowInfo;
}
- if ((this.initialization.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.initialization.checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.initialization.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
FlowInfo preInitInfo = null;
boolean shouldAnalyseResource = this.binding != null
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
index cec4f93fe..e3a702999 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
@@ -1,10 +1,9 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
* http://www.eclipse.org/legal/epl-v10.html
- * $Id: MessageSend.java 23405 2010-02-03 17:02:18Z stephan $
*
* Contributors:
* IBM Corporation - initial API and implementation
@@ -26,6 +25,9 @@
* bug 381445 - [compiler][resource] Can the resource leak check be made aware of Closeables.closeQuietly?
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * bug 382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
+ * Jesper S Moller - Contributions for
+ * Bug 378674 - "The method can be declared as static" is wrong
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -47,6 +49,7 @@ import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
+import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
import org.eclipse.jdt.internal.compiler.lookup.InvocationSite;
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
@@ -137,7 +140,6 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator;
* What: Work against signature weakening.
* How: Insert casts for return value if needed.
*
- * @version $Id: MessageSend.java 23405 2010-02-03 17:02:18Z stephan $
*/
public class MessageSend extends Expression implements InvocationSite {
@@ -206,14 +208,8 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
// accessing non-static method without an object
currentScope.resetDeclaringClassMethodStaticFlag(this.actualReceiverType);
}
- } else if (this.receiver.isThis()) {
- if ((this.receiver.bits & ASTNode.IsImplicitThis) == 0) {
- // explicit this receiver, not allowed in static context
- currentScope.resetEnclosingMethodStaticFlag();
- }
}
- FlowInfo conditionFlowInfo;
if (this.arguments != null) {
int length = this.arguments.length;
for (int i = 0; i < length; i++) {
@@ -221,36 +217,21 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
if ((argument.implicitConversion & TypeIds.UNBOXING) != 0) {
argument.checkNPE(currentScope, flowContext, flowInfo);
}
- if (this.receiver.resolvedType != null
- && this.receiver.resolvedType.id == TypeIds.T_OrgEclipseCoreRuntimeAssert
- && argument.resolvedType != null
- && argument.resolvedType.id == TypeIds.T_boolean) {
- Constant cst = argument.optimizedBooleanConstant();
- boolean isOptimizedTrueAssertion = cst != Constant.NotAConstant && cst.booleanValue() == true;
- boolean isOptimizedFalseAssertion = cst != Constant.NotAConstant && cst.booleanValue() == false;
- flowContext.tagBits |= FlowContext.HIDE_NULL_COMPARISON_WARNING;
- conditionFlowInfo = argument.analyseCode(currentScope, flowContext, flowInfo.copy());
- if (!wasInsideAssert) {
- flowContext.tagBits &= ~FlowContext.HIDE_NULL_COMPARISON_WARNING;
- }
- UnconditionalFlowInfo assertWhenTrueInfo = conditionFlowInfo.initsWhenTrue().unconditionalInits();
- FlowInfo assertInfo = conditionFlowInfo.initsWhenFalse();
- if (isOptimizedTrueAssertion) {
- assertInfo.setReachMode(FlowInfo.UNREACHABLE_OR_DEAD);
- }
- if (!isOptimizedFalseAssertion) {
- // if assertion is not false for sure, only then it makes sense to carry the flow info ahead.
- // if the code does reach ahead, it means the assert didn't cause an exit, and so
- // the expression inside it shouldn't change the prior flowinfo
- // viz. org.eclipse.core.runtime.Assert.isLegal(false && o != null)
-
- // keep the merge from the initial code for the definite assignment
- // analysis, tweak the null part to influence nulls downstream
- flowInfo = flowInfo.mergedWith(assertInfo.nullInfoLessUnconditionalCopy()).
- addInitializationsFrom(assertWhenTrueInfo.discardInitializationInfo());
- }
- } else {
- flowInfo = argument.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
+ switch (detectAssertionUtility(i)) {
+ case TRUE_ASSERTION:
+ flowInfo = analyseBooleanAssertion(currentScope, argument, flowContext, flowInfo, wasInsideAssert, true);
+ break;
+ case FALSE_ASSERTION:
+ flowInfo = analyseBooleanAssertion(currentScope, argument, flowContext, flowInfo, wasInsideAssert, false);
+ break;
+ case NONNULL_ASSERTION:
+ flowInfo = analyseNullAssertion(currentScope, argument, flowContext, flowInfo, false);
+ break;
+ case NULL_ASSERTION:
+ flowInfo = analyseNullAssertion(currentScope, argument, flowContext, flowInfo, true);
+ break;
+ default:
+ flowInfo = argument.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
}
if (analyseResources) {
// if argument is an AutoCloseable insert info that it *may* be closed (by the target method, i.e.)
@@ -316,6 +297,153 @@ protected FlowInfo checkBaseCallsIfSuper(BlockScope currentScope, FlowInfo flowI
return flowInfo;
}
// SH}
+
+// classification of well-known assertion utilities:
+private static final int TRUE_ASSERTION = 1;
+private static final int FALSE_ASSERTION = 2;
+private static final int NULL_ASSERTION = 3;
+private static final int NONNULL_ASSERTION = 4;
+
+// is the argument at the given position being checked by a well-known assertion utility?
+// if so answer what kind of assertion we are facing.
+private int detectAssertionUtility(int argumentIdx) {
+ TypeBinding[] parameters = this.binding.original().parameters;
+ if (argumentIdx < parameters.length) {
+ TypeBinding parameterType = parameters[argumentIdx];
+ if (this.actualReceiverType != null && parameterType != null) {
+ switch (this.actualReceiverType.id) {
+ case TypeIds.T_OrgEclipseCoreRuntimeAssert:
+ if (parameterType.id == TypeIds.T_boolean)
+ return TRUE_ASSERTION;
+ if (parameterType.id == TypeIds.T_JavaLangObject && CharOperation.equals(TypeConstants.IS_NOTNULL, this.selector))
+ return NONNULL_ASSERTION;
+ break;
+ case TypeIds.T_JunitFrameworkAssert:
+ case TypeIds.T_OrgJunitAssert:
+ if (parameterType.id == TypeIds.T_boolean) {
+ if (CharOperation.equals(TypeConstants.ASSERT_TRUE, this.selector))
+ return TRUE_ASSERTION;
+ if (CharOperation.equals(TypeConstants.ASSERT_FALSE, this.selector))
+ return FALSE_ASSERTION;
+ } else if (parameterType.id == TypeIds.T_JavaLangObject) {
+ if (CharOperation.equals(TypeConstants.ASSERT_NOTNULL, this.selector))
+ return NONNULL_ASSERTION;
+ if (CharOperation.equals(TypeConstants.ASSERT_NULL, this.selector))
+ return NULL_ASSERTION;
+ }
+ break;
+ case TypeIds.T_OrgApacheCommonsLangValidate:
+ if (parameterType.id == TypeIds.T_boolean) {
+ if (CharOperation.equals(TypeConstants.IS_TRUE, this.selector))
+ return TRUE_ASSERTION;
+ } else if (parameterType.id == TypeIds.T_JavaLangObject) {
+ if (CharOperation.equals(TypeConstants.NOT_NULL, this.selector))
+ return NONNULL_ASSERTION;
+ }
+ break;
+ case TypeIds.T_OrgApacheCommonsLang3Validate:
+ if (parameterType.id == TypeIds.T_boolean) {
+ if (CharOperation.equals(TypeConstants.IS_TRUE, this.selector))
+ return TRUE_ASSERTION;
+ } else if (parameterType.isTypeVariable()) {
+ if (CharOperation.equals(TypeConstants.NOT_NULL, this.selector))
+ return NONNULL_ASSERTION;
+ }
+ break;
+ case TypeIds.T_ComGoogleCommonBasePreconditions:
+ if (parameterType.id == TypeIds.T_boolean) {
+ if (CharOperation.equals(TypeConstants.CHECK_ARGUMENT, this.selector)
+ || CharOperation.equals(TypeConstants.CHECK_STATE, this.selector))
+ return TRUE_ASSERTION;
+ } else if (parameterType.isTypeVariable()) {
+ if (CharOperation.equals(TypeConstants.CHECK_NOT_NULL, this.selector))
+ return NONNULL_ASSERTION;
+ }
+ break;
+ case TypeIds.T_JavaUtilObjects:
+ if (parameterType.isTypeVariable()) {
+ if (CharOperation.equals(TypeConstants.REQUIRE_NON_NULL, this.selector))
+ return NONNULL_ASSERTION;
+ }
+ break;
+ }
+ }
+ }
+ return 0;
+}
+private FlowInfo analyseBooleanAssertion(BlockScope currentScope, Expression argument,
+ FlowContext flowContext, FlowInfo flowInfo, boolean wasInsideAssert, boolean passOnTrue)
+{
+ Constant cst = argument.optimizedBooleanConstant();
+ boolean isOptimizedTrueAssertion = cst != Constant.NotAConstant && cst.booleanValue() == true;
+ boolean isOptimizedFalseAssertion = cst != Constant.NotAConstant && cst.booleanValue() == false;
+ int tagBitsSave = flowContext.tagBits;
+ flowContext.tagBits |= FlowContext.HIDE_NULL_COMPARISON_WARNING;
+ if (!passOnTrue)
+ flowContext.tagBits |= FlowContext.INSIDE_NEGATIVE_ASSERT; // this affects syntactic analysis for fields in EqualExpression
+ FlowInfo conditionFlowInfo = argument.analyseCode(currentScope, flowContext, flowInfo.copy());
+ flowContext.extendTimeToLiveForNullCheckedField(2); // survive this assert as a MessageSend and as a Statement
+ flowContext.tagBits = tagBitsSave;
+
+ UnconditionalFlowInfo assertWhenPassInfo;
+ FlowInfo assertWhenFailInfo;
+ boolean isOptimizedPassing;
+ boolean isOptimizedFailing;
+ if (passOnTrue) {
+ assertWhenPassInfo = conditionFlowInfo.initsWhenTrue().unconditionalInits();
+ assertWhenFailInfo = conditionFlowInfo.initsWhenFalse();
+ isOptimizedPassing = isOptimizedTrueAssertion;
+ isOptimizedFailing = isOptimizedFalseAssertion;
+ } else {
+ assertWhenPassInfo = conditionFlowInfo.initsWhenFalse().unconditionalInits();
+ assertWhenFailInfo = conditionFlowInfo.initsWhenTrue();
+ isOptimizedPassing = isOptimizedFalseAssertion;
+ isOptimizedFailing = isOptimizedTrueAssertion;
+ }
+ if (isOptimizedPassing) {
+ assertWhenFailInfo.setReachMode(FlowInfo.UNREACHABLE_OR_DEAD);
+ }
+ if (!isOptimizedFailing) {
+ // if assertion is not failing for sure, only then it makes sense to carry the flow info ahead.
+ // if the code does reach ahead, it means the assert didn't cause an exit, and so
+ // the expression inside it shouldn't change the prior flowinfo
+ // viz. org.eclipse.core.runtime.Assert.isLegal(false && o != null)
+
+ // keep the merge from the initial code for the definite assignment
+ // analysis, tweak the null part to influence nulls downstream
+ flowInfo = flowInfo.mergedWith(assertWhenFailInfo.nullInfoLessUnconditionalCopy()).
+ addInitializationsFrom(assertWhenPassInfo.discardInitializationInfo());
+ }
+ return flowInfo;
+}
+private FlowInfo analyseNullAssertion(BlockScope currentScope, Expression argument,
+ FlowContext flowContext, FlowInfo flowInfo, boolean expectingNull)
+{
+ int nullStatus = argument.nullStatus(flowInfo, flowContext);
+ boolean willFail = (nullStatus == (expectingNull ? FlowInfo.NON_NULL : FlowInfo.NULL));
+ flowInfo = argument.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
+ LocalVariableBinding local = argument.localVariableBinding();
+ if (local != null) {// beyond this point the argument can only be null/nonnull
+ if (expectingNull)
+ flowInfo.markAsDefinitelyNull(local);
+ else
+ flowInfo.markAsDefinitelyNonNull(local);
+ } else {
+ if (!expectingNull
+ && argument instanceof Reference
+ && currentScope.compilerOptions().enableSyntacticNullAnalysisForFields)
+ {
+ FieldBinding field = ((Reference)argument).lastFieldBinding();
+ if (field != null && (field.type.tagBits & TagBits.IsBaseType) == 0) {
+ flowContext.recordNullCheckedFieldReference((Reference) argument, 3); // survive this assert as a MessageSend and as a Statement
+ }
+ }
+ }
+ if (willFail)
+ flowInfo.setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
+ return flowInfo;
+}
+
public boolean checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) {
// message send as a receiver
if ((nullStatus(flowInfo, flowContext) & FlowInfo.POTENTIALLY_NULL) != 0)
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
index 885caa76e..598c51a1a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -16,6 +16,8 @@
* bug 365519 - editorial cleanup after bug 186342 and bug 365387
* bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * Jesper S Moller <jesper@selskabet.org> - Contributions for
+ * bug 378674 - "The method can be declared as static" is wrong
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -30,7 +32,6 @@ import org.eclipse.jdt.internal.compiler.flow.ExceptionHandlingFlowContext;
import org.eclipse.jdt.internal.compiler.flow.FlowContext;
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
-import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding;
@@ -81,6 +82,7 @@ public class MethodDeclaration extends AbstractMethodDeclaration {
*/
public MethodDeclaration(CompilationResult compilationResult) {
super(compilationResult);
+ this.bits |= ASTNode.CanBeStatic; // Start with this assumption, will course correct during resolve and analyseCode.
}
public void analyseCode(ClassScope classScope, FlowContext flowContext, FlowInfo flowInfo) {
@@ -147,17 +149,6 @@ public class MethodDeclaration extends AbstractMethodDeclaration {
// nullity and mark as assigned
analyseArguments(flowInfo);
- if (this.arguments != null) {
- for (int i = 0, count = this.arguments.length; i < count; i++) {
- // if this method uses a type parameter declared by the declaring class,
- // it can't be static. https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682
- if (this.arguments[i].binding != null && (this.arguments[i].binding.type instanceof TypeVariableBinding)) {
- Binding declaringElement = ((TypeVariableBinding)this.arguments[i].binding.type).declaringElement;
- if (this.binding != null && this.binding.declaringClass == declaringElement)
- this.bits &= ~ASTNode.CanBeStatic;
- }
- }
- }
if (this.binding.declaringClass instanceof MemberTypeBinding && !this.binding.declaringClass.isStatic()) {
// method of a non-static member type can't be static.
this.bits &= ~ASTNode.CanBeStatic;
@@ -355,12 +346,12 @@ public class MethodDeclaration extends AbstractMethodDeclaration {
if ((this.modifiers & ClassFileConstants.AccAbstract) == 0)
this.scope.problemReporter().methodNeedBody(this);
} else {
- // the method HAS a body --> abstract native modifiers are forbiden
+ // the method HAS a body --> abstract native modifiers are forbidden
if (((this.modifiers & ClassFileConstants.AccNative) != 0) || ((this.modifiers & ClassFileConstants.AccAbstract) != 0))
this.scope.problemReporter().methodNeedingNoBody(this);
- else if (this.binding != null && !this.binding.isStatic() && !(this.binding.declaringClass instanceof LocalTypeBinding) && !returnsUndeclTypeVar) {
- // Not a method of local type - can be static
- this.bits |= ASTNode.CanBeStatic;
+ else if (this.binding == null || this.binding.isStatic() || (this.binding.declaringClass instanceof LocalTypeBinding) || returnsUndeclTypeVar) {
+ // Cannot be static for one of the reasons stated above
+ this.bits &= ~ASTNode.CanBeStatic;
}
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java
index d5e2ce9a4..a75400849 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java
@@ -23,6 +23,7 @@
* bug 388996 - [compiler][resource] Incorrect 'potential resource leak'
* bug 394768 - [compiler][resource] Incorrect resource leak warning when creating stream in conditional
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -58,9 +59,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
MethodScope methodScope = currentScope.methodScope();
if (this.expression != null) {
flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo);
- if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) {
- this.expression.checkNPE(currentScope, flowContext, flowInfo);
- }
+ this.expression.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
if (flowInfo.reachMode() == FlowInfo.REACHABLE)
checkAgainstNullAnnotation(currentScope, flowContext, this.expression.nullStatus(flowInfo, flowContext));
if (currentScope.compilerOptions().analyseResourceLeaks) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SuperReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SuperReference.java
index 5444d2adc..6dafc924f 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SuperReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SuperReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -7,12 +7,12 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Jesper S Moller - Contributions for
+ * Bug 378674 - "The method can be declared as static" is wrong
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
import org.eclipse.jdt.internal.compiler.ASTVisitor;
-import org.eclipse.jdt.internal.compiler.flow.FlowContext;
-import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
import org.eclipse.jdt.internal.compiler.impl.Constant;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
@@ -68,9 +68,4 @@ public class SuperReference extends ThisReference {
visitor.visit(this, blockScope);
visitor.endVisit(this, blockScope);
}
-
- public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) {
- currentScope.resetEnclosingMethodStaticFlag();
- return analyseCode(currentScope, flowContext, flowInfo);
- }
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ThisReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ThisReference.java
index 26327c452..87f1ec9f6 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ThisReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ThisReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -12,6 +12,8 @@
* Stephan Herrmann - Contribution for
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 383368 - [compiler][null] syntactic null analysis for field references
+ * Jesper S Moller - Contributions for
+ * Bug 378674 - "The method can be declared as static" is wrong
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -64,6 +66,7 @@ public class ThisReference extends Reference {
methodScope.problemReporter().errorThisSuperInStatic(this);
return false;
}
+ methodScope.resetEnclosingMethodStaticFlag();
return true;
}
@@ -148,13 +151,4 @@ public class ThisReference extends Reference {
visitor.visit(this, blockScope);
visitor.endVisit(this, blockScope);
}
-
- public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
- if (!isImplicitThis()) {
- // explicit this reference, not allowed in static context
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335780
- currentScope.resetEnclosingMethodStaticFlag();
- }
- return super.analyseCode(currentScope, flowContext, flowInfo);
- }
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java
index d978ac712..9a0cba71f 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -17,6 +17,8 @@
* bug 358903 - Filter practically unimportant resource leak warnings
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 388996 - [compiler][resource] Incorrect 'potential resource leak'
+ * bug 401088 - [compiler][null] Wrong warning "Redundant null check" inside nested try statement
+ * bug 401092 - [compiler][null] Wrong warning "Redundant null check" in outer catch of nested try
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -122,6 +124,11 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
if (this.subRoutineStartLabel == null) {
// no finally block -- this is a simplified copy of the else part
+ if (flowContext instanceof FinallyFlowContext) {
+ // if this TryStatement sits inside another TryStatement,
+ // report into the initsOnFinally of the outer try-block.
+ flowContext.initsOnFinally = ((FinallyFlowContext)flowContext).tryContext.initsOnFinally;
+ }
// process the try block in a context handling the local exceptions.
ExceptionHandlingFlowContext handlingContext =
//{ObjectTeams: make hookable:
@@ -257,7 +264,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
// chain up null info registry
if (flowContext.initsOnFinally != null) {
- flowContext.initsOnFinally.addNullInfoFrom(handlingContext.initsOnFinally);
+ flowContext.mergeFinallyNullInfo(handlingContext.initsOnFinally);
}
return tryInfo;
@@ -267,6 +274,11 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
UnconditionalFlowInfo subInfo;
// analyse finally block first
insideSubContext = new InsideSubRoutineFlowContext(flowContext, this);
+ if (flowContext instanceof FinallyFlowContext) {
+ // if this TryStatement sits inside another TryStatement,
+ // let the nested context report into the initsOnFinally of the outer try-block.
+ insideSubContext.initsOnFinally = ((FinallyFlowContext)flowContext).tryContext.initsOnFinally;
+ }
// process the try block in a context handling the local exceptions.
// (advance instantiation so we can wire this into the FinallyFlowContext)
@@ -431,7 +443,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
// chain up null info registry
if (flowContext.initsOnFinally != null) {
- flowContext.initsOnFinally.addNullInfoFrom(handlingContext.initsOnFinally);
+ flowContext.mergeFinallyNullInfo(handlingContext.initsOnFinally);
}
this.naturalExitMergeInitStateIndex =
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java
index 8f31b3e2e..407e5a6cf 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java
@@ -13,27 +13,14 @@
package org.eclipse.jdt.internal.compiler.classfmt;
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
-import org.eclipse.jdt.internal.compiler.util.Util;
class MethodInfoWithParameterAnnotations extends MethodInfoWithAnnotations {
private AnnotationInfo[][] parameterAnnotations;
MethodInfoWithParameterAnnotations(MethodInfo methodInfo, AnnotationInfo[] annotations, AnnotationInfo[][] parameterAnnotations) {
super(methodInfo, annotations);
- if (methodInfo.isConstructor()) {
- int parametersCount = Util.getParameterCount(methodInfo.getMethodDescriptor());
- if (parameterAnnotations.length < parametersCount) {
- AnnotationInfo[][] temp = new AnnotationInfo[parametersCount][];
- System.arraycopy(parameterAnnotations, 0, temp, 1, parameterAnnotations.length);
- this.parameterAnnotations = temp;
- } else {
- this.parameterAnnotations = parameterAnnotations;
- }
- } else {
- this.parameterAnnotations = parameterAnnotations;
- }
+ this.parameterAnnotations = parameterAnnotations;
}
-
public IBinaryAnnotation[] getParameterAnnotations(int index) {
return this.parameterAnnotations[index];
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java
index d8e5dddeb..664d24047 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java
@@ -79,6 +79,8 @@ public class FlowContext implements TypeConstants {
public static final int DEFER_NULL_DIAGNOSTIC = 0x1;
public static final int PREEMPT_NULL_DIAGNOSTIC = 0x2;
+ // inside an assertFalse checks for equality / inequality have reversed meaning for syntactic analysis for fields:
+ public static final int INSIDE_NEGATIVE_ASSERT = 0x4;
/**
* used to hide null comparison related warnings inside assert statements
*/
@@ -149,6 +151,13 @@ public void recordNullCheckedFieldReference(Reference reference, int timeToLive)
this.nullCheckedFieldReferences[len] = reference;
}
}
+
+/** If a null checked field has been recorded recently, increase its time to live. */
+public void extendTimeToLiveForNullCheckedField(int t) {
+ if (this.timeToLiveForNullCheckInfo > 0)
+ this.timeToLiveForNullCheckInfo += t;
+}
+
/**
* Forget any information about fields that were previously known to be non-null.
*
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
index 9b3f81188..6c8079293 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
@@ -1,10 +1,10 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Fraunhofer FIRST - extended API and implementation
@@ -17,6 +17,8 @@
* bug 365531 - [compiler][null] investigate alternative strategy for internally encoding nullness defaults
* bug 388281 - [compiler][null] inheritance of null annotations as an option
* bug 395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation.
+ * bug 400421 - [compiler] Null analysis for fields does not take @com.google.inject.Inject into account
+ * bug 382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
@@ -86,16 +88,15 @@ abstract public class ReferenceBinding extends AbstractOTReferenceBinding {
public PackageBinding fPackage;
//{ObjectTeams: accessible for sub-classes:
/* orig:
- char[] fileName;
- char[] constantPoolName;
- char[] signature;
+ char[] fileName;
+ char[] constantPoolName;
+ char[] signature;
:giro */
public char[] fileName;
public char[] constantPoolName;
protected char[] signature;
// SH}
-
private SimpleLookupTable compatibleCache;
int typeBits; // additional bits characterizing this type
@@ -346,56 +347,6 @@ public MethodBinding[] availableMethods() {
return methods();
}
-public FieldBinding[] unResolvedFields() {
- return Binding.NO_FIELDS;
-}
-
-/*
- * If a type - known to be a Closeable - is mentioned in one of our white lists
- * answer the typeBit for the white list (BitWrapperCloseable or BitResourceFreeCloseable).
- */
-protected int applyCloseableWhitelists() {
- switch (this.compoundName.length) {
- case 3:
- if (CharOperation.equals(TypeConstants.JAVA, this.compoundName[0])) {
- if (CharOperation.equals(TypeConstants.IO, this.compoundName[1])) {
- char[] simpleName = this.compoundName[2];
- int l = TypeConstants.JAVA_IO_WRAPPER_CLOSEABLES.length;
- for (int i = 0; i < l; i++) {
- if (CharOperation.equals(simpleName, TypeConstants.JAVA_IO_WRAPPER_CLOSEABLES[i]))
- return TypeIds.BitWrapperCloseable;
- }
- l = TypeConstants.JAVA_IO_RESOURCE_FREE_CLOSEABLES.length;
- for (int i = 0; i < l; i++) {
- if (CharOperation.equals(simpleName, TypeConstants.JAVA_IO_RESOURCE_FREE_CLOSEABLES[i]))
- return TypeIds.BitResourceFreeCloseable;
- }
- }
- }
- break;
- case 4:
- if (CharOperation.equals(TypeConstants.JAVA, this.compoundName[0])) {
- if (CharOperation.equals(TypeConstants.UTIL, this.compoundName[1])) {
- if (CharOperation.equals(TypeConstants.ZIP, this.compoundName[2])) {
- char[] simpleName = this.compoundName[3];
- int l = TypeConstants.JAVA_UTIL_ZIP_WRAPPER_CLOSEABLES.length;
- for (int i = 0; i < l; i++) {
- if (CharOperation.equals(simpleName, TypeConstants.JAVA_UTIL_ZIP_WRAPPER_CLOSEABLES[i]))
- return TypeIds.BitWrapperCloseable;
- }
- }
- }
- }
- break;
- }
- int l = TypeConstants.OTHER_WRAPPER_CLOSEABLES.length;
- for (int i = 0; i < l; i++) {
- if (CharOperation.equals(this.compoundName, TypeConstants.OTHER_WRAPPER_CLOSEABLES[i]))
- return TypeIds.BitWrapperCloseable;
- }
- return 0;
-}
-
/**
* Answer true if the receiver can be instantiated
*/
@@ -605,10 +556,34 @@ public void computeId() {
return;
}
// SH}
- if (!CharOperation.equals(TypeConstants.JAVA, this.compoundName[0]))
- return;
+ char[] packageName = this.compoundName[0];
+ // expect only java.*.* and javax.*.* and junit.*.* and org.junit.*
+ switch (packageName.length) {
+ case 3: // only one type in this group, yet:
+ if (CharOperation.equals(TypeConstants.ORG_JUNIT_ASSERT, this.compoundName))
+ this.id = TypeIds.T_OrgJunitAssert;
+ return;
+ case 4:
+ if (!CharOperation.equals(TypeConstants.JAVA, packageName))
+ return;
+ break; // continue below ...
+ case 5:
+ switch (packageName[1]) {
+ case 'a':
+ if (CharOperation.equals(TypeConstants.JAVAX_ANNOTATION_INJECT_INJECT, this.compoundName))
+ this.id = TypeIds.T_JavaxInjectInject;
+ return;
+ case 'u':
+ if (CharOperation.equals(TypeConstants.JUNIT_FRAMEWORK_ASSERT, this.compoundName))
+ this.id = TypeIds.T_JunitFrameworkAssert;
+ return;
+ }
+ return;
+ default: return;
+ }
+ // ... at this point we know it's java.*.*
- char[] packageName = this.compoundName[1];
+ packageName = this.compoundName[1];
if (packageName.length == 0) return; // just to be safe
char[] typeName = this.compoundName[2];
if (typeName.length == 0) return; // just to be safe
@@ -656,6 +631,10 @@ public void computeId() {
if (CharOperation.equals(typeName, TypeConstants.JAVA_UTIL_ITERATOR[2]))
this.id = TypeIds.T_JavaUtilIterator;
return;
+ case 'O' :
+ if (CharOperation.equals(typeName, TypeConstants.JAVA_UTIL_OBJECTS[2]))
+ this.id = TypeIds.T_JavaUtilObjects;
+ return;
}
}
return;
@@ -823,6 +802,12 @@ public void computeId() {
break;
case 4:
+ // expect one type from com.*.*.*:
+ if (CharOperation.equals(TypeConstants.COM_GOOGLE_INJECT_INJECT, this.compoundName)) {
+ this.id = TypeIds.T_ComGoogleInjectInject;
+ return;
+ }
+ // otherwise only expect java.*.*.*
if (!CharOperation.equals(TypeConstants.JAVA, this.compoundName[0]))
return;
packageName = this.compoundName[1];
@@ -940,29 +925,49 @@ public void computeId() {
packageName = this.compoundName[1];
if (packageName.length == 0) return; // just to be safe
- if (CharOperation.equals(TypeConstants.ECLIPSE, packageName)) {
- packageName = this.compoundName[2];
- if (packageName.length == 0) return; // just to be safe
- switch (packageName[0]) {
- case 'c' :
- if (CharOperation.equals(packageName, TypeConstants.CORE)) {
- typeName = this.compoundName[3];
- if (typeName.length == 0) return; // just to be safe
- switch (typeName[0]) {
- case 'r' :
- char[] memberTypeName = this.compoundName[4];
- if (memberTypeName.length == 0) return; // just to be safe
- if (CharOperation.equals(typeName, TypeConstants.ORG_ECLIPSE_CORE_RUNTIME_ASSERT[3])
- && CharOperation.equals(memberTypeName, TypeConstants.ORG_ECLIPSE_CORE_RUNTIME_ASSERT[4]))
- this.id = TypeIds.T_OrgEclipseCoreRuntimeAssert;
- return;
- }
+ switch (packageName[0]) {
+ case 'e':
+ if (CharOperation.equals(TypeConstants.ECLIPSE, packageName)) {
+ packageName = this.compoundName[2];
+ if (packageName.length == 0) return; // just to be safe
+ switch (packageName[0]) {
+ case 'c' :
+ if (CharOperation.equals(packageName, TypeConstants.CORE)) {
+ typeName = this.compoundName[3];
+ if (typeName.length == 0) return; // just to be safe
+ switch (typeName[0]) {
+ case 'r' :
+ char[] memberTypeName = this.compoundName[4];
+ if (memberTypeName.length == 0) return; // just to be safe
+ if (CharOperation.equals(typeName, TypeConstants.ORG_ECLIPSE_CORE_RUNTIME_ASSERT[3])
+ && CharOperation.equals(memberTypeName, TypeConstants.ORG_ECLIPSE_CORE_RUNTIME_ASSERT[4]))
+ this.id = TypeIds.T_OrgEclipseCoreRuntimeAssert;
+ return;
+ }
+ }
+ return;
}
return;
- }
- return;
+ }
+ return;
+ case 'a':
+ if (CharOperation.equals(TypeConstants.APACHE, packageName)) {
+ if (CharOperation.equals(TypeConstants.COMMONS, this.compoundName[2])) {
+ if (CharOperation.equals(TypeConstants.ORG_APACHE_COMMONS_LANG_VALIDATE, this.compoundName))
+ this.id = TypeIds.T_OrgApacheCommonsLangValidate;
+ else if (CharOperation.equals(TypeConstants.ORG_APACHE_COMMONS_LANG3_VALIDATE, this.compoundName))
+ this.id = TypeIds.T_OrgApacheCommonsLang3Validate;
+ }
+ }
+ return;
}
return;
+ case 'c':
+ if (!CharOperation.equals(TypeConstants.COM, this.compoundName[0]))
+ return;
+ if (CharOperation.equals(TypeConstants.COM_GOOGLE_COMMON_BASE_PRECONDITIONS, this.compoundName))
+ this.id = TypeIds.T_ComGoogleCommonBasePreconditions;
+ return;
}
break;
}
@@ -991,6 +996,7 @@ public char[] attributeName() /* p1.p2.COuter$CInner */ {
return CharOperation.concatWith(this.compoundName, '.');
}
// SH}
+
public String debugName() {
return (this.compoundName != null) ? new String(readableName()) : "UNNAMED TYPE"; //$NON-NLS-1$
}
@@ -1085,12 +1091,6 @@ public long getAnnotationTagBits() {
return this.tagBits;
}
-// Answer methods named selector, which take no more than the suggestedParameterLength.
-// The suggested parameter length is optional and may not be guaranteed by every type.
-public MethodBinding[] getMethods(char[] selector, int suggestedParameterLength) {
- return getMethods(selector);
-}
-
/**
* @return the enclosingInstancesSlotSize
*/
@@ -1115,8 +1115,6 @@ public FieldBinding getField(char[] fieldName, boolean needResolve) {
public char[] getFileName() {
return this.fileName;
}
-/** Answer an additional bit characterizing this type, like {@link TypeIds#BitAutoCloseable}. */
-abstract public boolean hasTypeBit(int bit);
public ReferenceBinding getMemberType(char[] typeName) {
ReferenceBinding[] memberTypes = memberTypes();
@@ -1142,6 +1140,13 @@ public ReferenceBinding getMemberTypeRecurse(char[] typeName) {
public MethodBinding[] getMethods(char[] selector) {
return Binding.NO_METHODS;
}
+
+// Answer methods named selector, which take no more than the suggestedParameterLength.
+// The suggested parameter length is optional and may not be guaranteed by every type.
+public MethodBinding[] getMethods(char[] selector, int suggestedParameterLength) {
+ return getMethods(selector);
+}
+
//{ObjectTeams:
/**
* get method by its selector, search includes superclasses, superinterfaces.
@@ -1331,6 +1336,8 @@ boolean hasNonNullDefault() {
public final boolean hasRestrictedAccess() {
return (this.modifiers & ExtraCompilerModifiers.AccRestrictedAccess) != 0;
}
+/** Answer an additional bit characterizing this type, like {@link TypeIds#BitAutoCloseable}. */
+abstract public boolean hasTypeBit(int bit);
//{ObjectTeams: support asymmetric comparison. // FIXME(SH): is this needed or is super-impl smart enough??
@Override
@@ -1927,7 +1934,7 @@ public char[] shortReadableName() /*Object*/ {
}
return shortReadableName;
}
-// SH} // end sourceName - editid section
+// SH} // end sourceName - edited section
//{ObjectTeams: to be overridden in RoleTypeBinding
public char[] optimalName() {
@@ -2020,6 +2027,57 @@ public SyntheticArgumentBinding[] syntheticOuterLocalVariables() {
MethodBinding[] unResolvedMethods() { // for the MethodVerifier so it doesn't resolve types
return methods();
}
+
+public FieldBinding[] unResolvedFields() {
+ return Binding.NO_FIELDS;
+}
+
+/*
+ * If a type - known to be a Closeable - is mentioned in one of our white lists
+ * answer the typeBit for the white list (BitWrapperCloseable or BitResourceFreeCloseable).
+ */
+protected int applyCloseableWhitelists() {
+ switch (this.compoundName.length) {
+ case 3:
+ if (CharOperation.equals(TypeConstants.JAVA, this.compoundName[0])) {
+ if (CharOperation.equals(TypeConstants.IO, this.compoundName[1])) {
+ char[] simpleName = this.compoundName[2];
+ int l = TypeConstants.JAVA_IO_WRAPPER_CLOSEABLES.length;
+ for (int i = 0; i < l; i++) {
+ if (CharOperation.equals(simpleName, TypeConstants.JAVA_IO_WRAPPER_CLOSEABLES[i]))
+ return TypeIds.BitWrapperCloseable;
+ }
+ l = TypeConstants.JAVA_IO_RESOURCE_FREE_CLOSEABLES.length;
+ for (int i = 0; i < l; i++) {
+ if (CharOperation.equals(simpleName, TypeConstants.JAVA_IO_RESOURCE_FREE_CLOSEABLES[i]))
+ return TypeIds.BitResourceFreeCloseable;
+ }
+ }
+ }
+ break;
+ case 4:
+ if (CharOperation.equals(TypeConstants.JAVA, this.compoundName[0])) {
+ if (CharOperation.equals(TypeConstants.UTIL, this.compoundName[1])) {
+ if (CharOperation.equals(TypeConstants.ZIP, this.compoundName[2])) {
+ char[] simpleName = this.compoundName[3];
+ int l = TypeConstants.JAVA_UTIL_ZIP_WRAPPER_CLOSEABLES.length;
+ for (int i = 0; i < l; i++) {
+ if (CharOperation.equals(simpleName, TypeConstants.JAVA_UTIL_ZIP_WRAPPER_CLOSEABLES[i]))
+ return TypeIds.BitWrapperCloseable;
+ }
+ }
+ }
+ }
+ break;
+ }
+ int l = TypeConstants.OTHER_WRAPPER_CLOSEABLES.length;
+ for (int i = 0; i < l; i++) {
+ if (CharOperation.equals(this.compoundName, TypeConstants.OTHER_WRAPPER_CLOSEABLES[i]))
+ return TypeIds.BitWrapperCloseable;
+ }
+ return 0;
+}
+
//{ObjectTeams: support for checking substitution of a value parameter
public VariableBinding valueParamSynthArgAt(int typeParamPosition) {
SyntheticArgumentBinding[] args = valueParamSynthArgs();
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
index d27ed0ec8..9e72b0f8e 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -14,6 +14,10 @@
* bug 186342 - [compiler][null] Using annotations for null checking
* bug 387612 - Unreachable catch block...exception is never thrown from the try
* bug 395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation.
+ * bug 401456 - Code compiles from javac/intellij, but fails from eclipse
+ * bug 401271 - StackOverflowError when searching for a methods references
+ * Jesper S Moller - Contributions for
+ * Bug 378674 - "The method can be declared as static" is wrong
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
@@ -416,13 +420,12 @@ public abstract class Scope {
/**
* Returns a type, where original type was substituted using the receiver
* parameterized type.
- * In raw mode, all parameterized type denoting same original type are converted
- * to raw types. e.g.
- * class X <T> {
- * X<T> foo;
- * X<String> bar;
- * } when used in raw fashion, then type of both foo and bar is raw type X.
- *
+ * In raw mode (see {@link Substitution#isRawSubstitution()}),
+ * all parameterized types are converted to raw types.
+ * Cf. 4.8: "The type of a constructor (8.8), instance method (8.4, 9.4),
+ * or non-static field (8.3) M of a raw type C that is not inherited from its
+ * superclasses or superinterfaces is the raw type that corresponds to the erasure
+ * of its type in the generic declaration corresponding to C."
*/
public static TypeBinding substitute(Substitution substitution, TypeBinding originalType) {
if (originalType == null) return null;
@@ -441,6 +444,9 @@ public abstract class Scope {
ReferenceBinding substitutedEnclosing = originalEnclosing;
if (originalEnclosing != null) {
substitutedEnclosing = (ReferenceBinding) substitute(substitution, originalEnclosing);
+ if (isMemberTypeOfRaw(originalType, substitutedEnclosing))
+ return originalParameterizedType.environment.createRawType(
+ originalParameterizedType.genericType(), substitutedEnclosing);
}
TypeBinding[] originalArguments = originalParameterizedType.arguments;
TypeBinding[] substitutedArguments = originalArguments;
@@ -511,6 +517,8 @@ public abstract class Scope {
substitutedEnclosing = originalEnclosing;
if (originalEnclosing != null) {
substitutedEnclosing = (ReferenceBinding) substitute(substitution, originalEnclosing);
+ if (isMemberTypeOfRaw(originalType, substitutedEnclosing))
+ return substitution.environment().createRawType(originalReferenceType, substitutedEnclosing);
}
// treat as if parameterized with its type variables (non generic type gets 'null' arguments)
@@ -526,6 +534,8 @@ public abstract class Scope {
substitutedEnclosing = originalEnclosing;
if (originalEnclosing != null) {
substitutedEnclosing = (ReferenceBinding) substitute(substitution, originalEnclosing);
+ if (isMemberTypeOfRaw(originalType, substitutedEnclosing))
+ return substitution.environment().createRawType(originalReferenceType, substitutedEnclosing);
}
if (substitution.isRawSubstitution()) {
@@ -539,6 +549,19 @@ public abstract class Scope {
return originalType;
}
+ private static boolean isMemberTypeOfRaw(TypeBinding originalType, ReferenceBinding substitutedEnclosing) {
+ // 4.8:
+ // "a raw type is defined to be one of:
+ // ...
+ // * A non-static member type of a raw type R that is not
+ // inherited from a superclass or superinterface of R."
+
+ // Due to staticness, e.g., Map.Entry<String,Object> is *not* considered as a raw type
+
+ return (substitutedEnclosing != null && substitutedEnclosing.isRawType())
+ && ((originalType instanceof ReferenceBinding) && !((ReferenceBinding)originalType).isStatic());
+ }
+
/**
* Returns an array of types, where original types got substituted given a substitution.
* Only allocate an array if anything is different.
@@ -1885,13 +1908,14 @@ public abstract class Scope {
ProblemFieldBinding foundInsideProblem = null;
// inside Constructor call or inside static context
Scope scope = this;
+ MethodScope methodScope = null;
int depth = 0;
int foundDepth = 0;
ReferenceBinding foundActualReceiverType = null;
done : while (true) { // done when a COMPILATION_UNIT_SCOPE is found
switch (scope.kind) {
case METHOD_SCOPE :
- MethodScope methodScope = (MethodScope) scope;
+ methodScope = (MethodScope) scope;
insideStaticContext |= methodScope.isStatic;
insideConstructorCall |= methodScope.isConstructorCall;
insideTypeAnnotation = methodScope.insideTypeAnnotation;
@@ -1956,6 +1980,8 @@ public abstract class Scope {
fieldBinding.declaringClass,
name,
ProblemReasons.NonStaticReferenceInStaticContext);
+ } else if (methodScope != null) {
+ methodScope.resetEnclosingMethodStaticFlag();
}
}
if (receiverType == fieldBinding.declaringClass || compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) {
@@ -2303,6 +2329,7 @@ public abstract class Scope {
MethodBinding foundProblem = null;
boolean foundProblemVisible = false;
Scope scope = this;
+ MethodScope methodScope = null;
int depth = 0;
// in 1.4 mode (inherited visible shadows enclosing)
CompilerOptions options;
@@ -2311,7 +2338,7 @@ public abstract class Scope {
done : while (true) { // done when a COMPILATION_UNIT_SCOPE is found
switch (scope.kind) {
case METHOD_SCOPE :
- MethodScope methodScope = (MethodScope) scope;
+ methodScope = (MethodScope) scope;
insideStaticContext |= methodScope.isStatic;
insideConstructorCall |= methodScope.isConstructorCall;
insideTypeAnnotation = methodScope.insideTypeAnnotation;
@@ -2350,6 +2377,8 @@ public abstract class Scope {
insideConstructorCall
? ProblemReasons.NonStaticReferenceInConstructorInvocation
: ProblemReasons.NonStaticReferenceInStaticContext);
+ } else if (!methodBinding.isStatic() && methodScope != null) {
+ methodScope.resetDeclaringClassMethodStaticFlag(receiverType);
}
if (inheritedHasPrecedence
|| receiverType == methodBinding.declaringClass
@@ -2961,6 +2990,7 @@ public abstract class Scope {
private final Binding internalGetTypeOrPackage(char[] name, int mask, boolean needResolve) {
// SH}
Scope scope = this;
+ MethodScope methodScope = null;
ReferenceBinding foundType = null;
boolean insideStaticContext = false;
boolean insideTypeAnnotation = false;
@@ -2977,7 +3007,7 @@ public abstract class Scope {
done : while (true) { // done when a COMPILATION_UNIT_SCOPE is found
switch (scope.kind) {
case METHOD_SCOPE :
- MethodScope methodScope = (MethodScope) scope;
+ methodScope = (MethodScope) scope;
AbstractMethodDeclaration methodDecl = methodScope.referenceMethod();
if (methodDecl != null) {
if (methodDecl.binding != null) {
@@ -3065,6 +3095,8 @@ public abstract class Scope {
if (typeVariable != null) {
if (insideStaticContext) // do not consider this type modifiers: access is legite within same type
return new ProblemReferenceBinding(new char[][]{name}, typeVariable, ProblemReasons.NonStaticReferenceInStaticContext);
+ else if (methodScope != null)
+ methodScope.resetEnclosingMethodStaticFlag();
return typeVariable;
}
insideStaticContext |= sourceType.isStatic();
@@ -3131,53 +3163,11 @@ public abstract class Scope {
}
}
}
- // walk single static imports. A type found here will shadow types with same name in other CU's, or types coming
- // from on-demand imports. JLS 7.5.3
+ // In this location we had a fix for
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318401
- if (imports != null) {
- ReferenceBinding type = null;
- nextImport : for (int i = 0, length = imports.length; i < length; i++) {
- ImportBinding importBinding = imports[i];
- if (importBinding.isStatic()) {
- ReferenceBinding temp = null;
- if (CharOperation.equals(importBinding.compoundName[importBinding.compoundName.length - 1], name)) {
- Binding resolvedImport = importBinding.resolvedImport;
- if (resolvedImport == null) continue nextImport;
- if (resolvedImport instanceof MethodBinding || resolvedImport instanceof FieldBinding) {
- // check to see if there are also member types with the same name
- // must find the importRef's type again since the method/field can be from an inherited type
- // see StaticImportTest#test084 for more clarity
- char[][] importName = importBinding.reference.tokens;
- TypeBinding referencedType = getType(importName, importName.length - 1);
- if (referencedType != null && referencedType instanceof ReferenceBinding) {
- temp = findMemberType(name, (ReferenceBinding) referencedType);
- }
- }
- if (temp != null && temp.isStatic() && temp != type) {
- if (temp.isValidBinding()) {
- if (!temp.canBeSeenBy(unitScope.fPackage)) {
- // Answer error binding - type is not visible
- foundType = new ProblemReferenceBinding(new char[][]{name}, type, ProblemReasons.NotVisible);
- } else {
- ImportReference importReference = importBinding.reference;
- if (importReference != null) {
- importReference.bits |= ASTNode.Used;
- }
- type = temp;
- }
- } else if (foundType == null) {
- foundType = temp;
- }
- }
- }
- }
- }
- if (type != null) {
- if (typeOrPackageCache != null)
- typeOrPackageCache.put(name, type);
- return type;
- }
- }
+ // However, as of today (4.3M6 candidate) this fix seems unnecessary, while causing StackOverflowError in
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=401271
+
// check if the name is in the current package, skip it if its a sub-package
PackageBinding currentPackage = unitScope.fPackage;
unitScope.recordReference(currentPackage.compoundName, name);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java
index ff9302b1c..d6a517466 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -11,6 +11,8 @@
* bug 349326 - [1.7] new warning for missing try-with-resources
* bug 358903 - Filter practically unimportant resource leak warnings
* bug 381445 - [compiler][resource] Can the resource leak check be made aware of Closeables.closeQuietly?
+ * bug 400421 - [compiler] Null analysis for fields does not take @com.google.inject.Inject into account
+ * bug 382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
@@ -81,6 +83,17 @@ public interface TypeConstants {
char[] UPPER_LOCAL_VARIABLE = "LOCAL_VARIABLE".toCharArray(); //$NON-NLS-1$
char[] UPPER_ANNOTATION_TYPE = "ANNOTATION_TYPE".toCharArray(); //$NON-NLS-1$
char[] UPPER_PACKAGE = "PACKAGE".toCharArray(); //$NON-NLS-1$
+
+ // common 3rd party package components:
+ char[] ORG = "org".toCharArray(); //$NON-NLS-1$
+ char[] ECLIPSE = "eclipse".toCharArray(); //$NON-NLS-1$
+ char[] CORE = "core".toCharArray(); //$NON-NLS-1$
+ char[] RUNTIME = "runtime".toCharArray(); //$NON-NLS-1$
+ char[] APACHE = "apache".toCharArray(); //$NON-NLS-1$
+ char[] COMMONS = "commons".toCharArray(); //$NON-NLS-1$
+ char[] LANG3 = "lang3".toCharArray(); //$NON-NLS-1$
+ char[] COM = "com".toCharArray(); //$NON-NLS-1$
+ char[] GOOGLE = "google".toCharArray(); //$NON-NLS-1$
// Constant compound names
char[][] JAVA_LANG = {JAVA, LANG};
@@ -117,6 +130,7 @@ public interface TypeConstants {
char[][] JAVA_LANG_VOID = {JAVA, LANG, "Void".toCharArray()}; //$NON-NLS-1$
char[][] JAVA_UTIL_COLLECTION = {JAVA, UTIL, "Collection".toCharArray()}; //$NON-NLS-1$
char[][] JAVA_UTIL_ITERATOR = {JAVA, UTIL, "Iterator".toCharArray()}; //$NON-NLS-1$
+ char[][] JAVA_UTIL_OBJECTS = {JAVA, UTIL, "Objects".toCharArray()}; //$NON-NLS-1$
char[][] JAVA_LANG_DEPRECATED = {JAVA, LANG, "Deprecated".toCharArray()}; //$NON-NLS-1$
char[][] JAVA_LANG_ANNOTATION_DOCUMENTED = {JAVA, LANG, ANNOTATION, "Documented".toCharArray()}; //$NON-NLS-1$
char[][] JAVA_LANG_ANNOTATION_INHERITED = {JAVA, LANG, ANNOTATION, "Inherited".toCharArray()}; //$NON-NLS-1$
@@ -167,12 +181,13 @@ public interface TypeConstants {
this.selector = selector;
}
}
- char[][] GUAVA_CLOSEABLES = { "com".toCharArray(), "google".toCharArray(), "common".toCharArray(), "io".toCharArray(), "Closeables".toCharArray() }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- char[][] APACHE_IOUTILS = { "org".toCharArray(), "apache".toCharArray(), "commons".toCharArray(), "io".toCharArray(), "IOUtils".toCharArray() }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ char[][] GUAVA_CLOSEABLES = { COM, GOOGLE, "common".toCharArray(), IO, "Closeables".toCharArray() }; //$NON-NLS-1$ //$NON-NLS-2$
+ char[][] APACHE_IOUTILS = { ORG, APACHE, COMMONS, IO, "IOUtils".toCharArray() }; //$NON-NLS-1$
+ char[] CLOSE_QUIETLY = "closeQuietly".toCharArray(); //$NON-NLS-1$
CloseMethodRecord[] closeMethods = new CloseMethodRecord[] {
- new CloseMethodRecord(GUAVA_CLOSEABLES, "closeQuietly".toCharArray()), //$NON-NLS-1$
- new CloseMethodRecord(GUAVA_CLOSEABLES, "close".toCharArray()), //$NON-NLS-1$
- new CloseMethodRecord(APACHE_IOUTILS, "closeQuietly".toCharArray()) //$NON-NLS-1$
+ new CloseMethodRecord(GUAVA_CLOSEABLES, CLOSE_QUIETLY),
+ new CloseMethodRecord(GUAVA_CLOSEABLES, CLOSE),
+ new CloseMethodRecord(APACHE_IOUTILS, CLOSE_QUIETLY)
};
// white lists of closeables:
char[][] JAVA_IO_WRAPPER_CLOSEABLES = new char[][] {
@@ -228,11 +243,46 @@ public interface TypeConstants {
"StringBufferInputStream".toCharArray(), //$NON-NLS-1$
};
- char[] ORG = "org".toCharArray(); //$NON-NLS-1$
- char[] ECLIPSE = "eclipse".toCharArray(); //$NON-NLS-1$
- char[] CORE = "core".toCharArray(); //$NON-NLS-1$
- char[] RUNTIME = "runtime".toCharArray(); //$NON-NLS-1$
- char[][] ORG_ECLIPSE_CORE_RUNTIME_ASSERT = new char[][] { ORG, ECLIPSE, CORE, RUNTIME, "Assert".toCharArray()}; //$NON-NLS-1$
+ // different assertion utilities:
+ char[] ASSERT_CLASS = "Assert".toCharArray(); //$NON-NLS-1$
+ char[][] ORG_ECLIPSE_CORE_RUNTIME_ASSERT = new char[][] { ORG, ECLIPSE, CORE, RUNTIME, ASSERT_CLASS };
+ // ... methods:
+ char[] IS_NOTNULL = "isNotNull".toCharArray(); //$NON-NLS-1$
+
+ char[] JUNIT = "junit".toCharArray(); //$NON-NLS-1$
+ char[] FRAMEWORK = "framework".toCharArray(); //$NON-NLS-1$
+ char[][] JUNIT_FRAMEWORK_ASSERT = new char[][] { JUNIT, FRAMEWORK, ASSERT_CLASS };
+ char[][] ORG_JUNIT_ASSERT = new char[][] { ORG, JUNIT, ASSERT_CLASS };
+ // ... methods:
+ char[] ASSERT_NULL = "assertNull".toCharArray(); //$NON-NLS-1$
+ char[] ASSERT_NOTNULL = "assertNotNull".toCharArray(); //$NON-NLS-1$
+ char[] ASSERT_TRUE = "assertTrue".toCharArray(); //$NON-NLS-1$
+ char[] ASSERT_FALSE = "assertFalse".toCharArray(); //$NON-NLS-1$
+
+ char[] VALIDATE_CLASS = "Validate".toCharArray(); //$NON-NLS-1$
+ char[][] ORG_APACHE_COMMONS_LANG_VALIDATE = new char[][] { ORG, APACHE, COMMONS, LANG, VALIDATE_CLASS };
+ char[][] ORG_APACHE_COMMONS_LANG3_VALIDATE = new char[][] { ORG, APACHE, COMMONS, LANG3, VALIDATE_CLASS };
+ // ... methods:
+ char[] IS_TRUE = "isTrue".toCharArray(); //$NON-NLS-1$
+ char[] NOT_NULL = "notNull".toCharArray(); //$NON-NLS-1$
+
+ char[][] COM_GOOGLE_COMMON_BASE_PRECONDITIONS = new char[][] {
+ COM, GOOGLE, "common".toCharArray(), "base".toCharArray(), "Preconditions".toCharArray() }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ // ... methods:
+ char[] CHECK_NOT_NULL = "checkNotNull".toCharArray(); //$NON-NLS-1$
+ char[] CHECK_ARGUMENT = "checkArgument".toCharArray(); //$NON-NLS-1$
+ char[] CHECK_STATE = "checkState".toCharArray(); //$NON-NLS-1$
+
+ // ... methods in java.util.Objects:
+ char[] REQUIRE_NON_NULL = "requireNonNull".toCharArray(); //$NON-NLS-1$
+
+ // different @Inject annotations are relevant for @NonNull fields
+ char[] INJECT_PACKAGE = "inject".toCharArray(); //$NON-NLS-1$
+ char[] INJECT_TYPE = "Inject".toCharArray(); //$NON-NLS-1$
+ char[][] JAVAX_ANNOTATION_INJECT_INJECT = new char[][] { JAVAX, INJECT_PACKAGE, INJECT_TYPE };
+ char[][] COM_GOOGLE_INJECT_INJECT = new char[][] {COM, GOOGLE, INJECT_PACKAGE, INJECT_TYPE };
+ // detail for the above:
+ char[] OPTIONAL = "optional".toCharArray(); //$NON-NLS-1$
// Constraints for generic type argument inference
int CONSTRAINT_EQUAL = 0; // Actual = Formal
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java
index cf057f4b8..5703e17c1 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -12,6 +12,8 @@
* bug 359362 - FUP of bug 349326: Resource leak on non-Closeable resource
* bug 186342 - [compiler][null] Using annotations for null checking
* bug 358903 - Filter practically unimportant resource leak warnings
+ * bug 400421 - [compiler] Null analysis for fields does not take @com.google.inject.Inject into account
+ * bug 382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
@@ -109,6 +111,18 @@ public interface TypeIds {
// new in 3.8 to identify org.eclipse.core.runtime.Assert
final int T_OrgEclipseCoreRuntimeAssert = 68;
+ // new in 3.9 to identify more assertion utilities:
+ final int T_JunitFrameworkAssert = 69;
+ final int T_OrgJunitAssert = 70;
+ final int T_OrgApacheCommonsLangValidate = 71;
+ final int T_OrgApacheCommonsLang3Validate = 72;
+ final int T_ComGoogleCommonBasePreconditions = 73;
+ final int T_JavaUtilObjects = 74;
+
+ // new in 3.9 to identify known @Inject annotations
+ final int T_JavaxInjectInject = 80;
+ final int T_ComGoogleInjectInject = 81;
+
final int NoId = Integer.MAX_VALUE;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java
index 8eae08107..326a7fd8b 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -1657,7 +1657,7 @@ public abstract class AbstractCommentParser implements JavadocTagConstants {
if (peekChar() == '}') {
if (domParser) {
createTag();
- pushText(textPosition, this.starPosition);
+ pushText(textPosition, this.index);
}
return true;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java
index 639cd9ac2..248f517d5 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -93,6 +93,7 @@ public class JavadocParser extends AbstractCommentParser {
// Parse
try {
this.source = this.sourceParser.scanner.source;
+ this.scanner.setSource(this.source); // updating source in scanner
if (this.checkDocComment) {
// Initialization
this.scanner.lineEnds = this.sourceParser.scanner.lineEnds;
@@ -141,6 +142,7 @@ public class JavadocParser extends AbstractCommentParser {
}
} finally {
this.source = null; // release source as soon as finished
+ this.scanner.setSource((char[]) null); //release source in scanner
}
return this.deprecated;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
index 0ab0f2d51..35362dd3c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
@@ -14,6 +14,9 @@
* bug 366003 - CCE in ASTNode.resolveAnnotations(ASTNode.java:639)
* bug 374605 - Unreasonable warning for enum-based switch statements
* bug 393719 - [compiler] inconsistent warnings on iteration variables
+ *
+ * Jesper S Moller - Contributions for
+ * bug 393192 - Incomplete type hierarchy with > 10 annotations
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.parser;
@@ -12281,6 +12284,7 @@ protected void parse() {
this.dietInt = oldDietInt;
}
//SH}
+ this.problemReporter.referenceContext = null; // Null this so we won't escalate problems needlessly (bug 393192)
if (DEBUG) System.out.println("-- EXIT FROM PARSE METHOD --"); //$NON-NLS-1$
}
public void parse(ConstructorDeclaration cd, CompilationUnitDeclaration unit, boolean recordLineSeparator) {
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 9afa1200f..03d30dadf 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
@@ -26,6 +26,8 @@
* bug 393719 - [compiler] inconsistent warnings on iteration variables
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 382789 - [compiler][null] warn when syntactically-nonnull expression is compared against null
+ * bug 376590 - Private fields with @Inject are ignored by unused field validation
+ * bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.problem;
@@ -364,10 +366,14 @@ public static int getIrritant(int problemID) {
case IProblem.NullLocalVariableReference:
case IProblem.NullableFieldReference:
+ case IProblem.NullExpressionReference:
+ case IProblem.NullUnboxing:
return CompilerOptions.NullReference;
case IProblem.PotentialNullLocalVariableReference:
case IProblem.PotentialNullMessageSendReference:
+ case IProblem.PotentialNullExpressionReference:
+ case IProblem.PotentialNullUnboxing:
return CompilerOptions.PotentialNullReference;
case IProblem.RedundantLocalVariableNullAssignment:
@@ -5862,6 +5868,10 @@ public void localVariableNullInstanceof(LocalVariableBinding local, ASTNode loca
}
public void localVariableNullReference(LocalVariableBinding local, ASTNode location) {
+ if (location instanceof Expression && (((Expression)location).implicitConversion & TypeIds.UNBOXING) != 0) {
+ nullUnboxing(location, local.type);
+ return;
+ }
int severity = computeSeverity(IProblem.NullLocalVariableReference);
if (severity == ProblemSeverities.Ignore) return;
String[] arguments = new String[] {new String(local.name) };
@@ -5883,6 +5893,10 @@ public void localVariableNullReference(LocalVariableBinding local, ASTNode locat
}
public void localVariablePotentialNullReference(LocalVariableBinding local, ASTNode location) {
+ if (location instanceof Expression && (((Expression)location).implicitConversion & TypeIds.UNBOXING) != 0) {
+ potentialNullUnboxing(location, local.type);
+ return;
+ }
int severity = computeSeverity(IProblem.PotentialNullLocalVariableReference);
if (severity == ProblemSeverities.Ignore) return;
String[] arguments = new String[] {new String(local.name)};
@@ -5902,7 +5916,16 @@ public void localVariablePotentialNullReference(LocalVariableBinding local, ASTN
nodeSourceStart(local, location),
nodeSourceEnd(local, location));
}
-
+public void potentialNullUnboxing(ASTNode expression, TypeBinding boxType) {
+ String[] arguments = new String[] { String.valueOf(boxType.readableName()) };
+ String[] argumentsShort = new String[] { String.valueOf(boxType.shortReadableName()) };
+ this.handle(IProblem.PotentialNullUnboxing, arguments, argumentsShort, expression.sourceStart, expression.sourceEnd);
+}
+public void nullUnboxing(ASTNode expression, TypeBinding boxType) {
+ String[] arguments = new String[] { String.valueOf(boxType.readableName()) };
+ String[] argumentsShort = new String[] { String.valueOf(boxType.shortReadableName()) };
+ this.handle(IProblem.NullUnboxing, arguments, argumentsShort, expression.sourceStart, expression.sourceEnd);
+}
public void nullableFieldDereference(VariableBinding variable, long position) {
String[] arguments = new String[] {new String(variable.name)};
char[][] nullableName = this.options.nullableAnnotationName;
@@ -8579,7 +8602,7 @@ public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
int severity = computeSeverity(IProblem.UnusedPrivateConstructor);
if (severity == ProblemSeverities.Ignore) return;
- if (excludeDueToAnnotation(constructorDecl.annotations)) return;
+ if (excludeDueToAnnotation(constructorDecl.annotations, IProblem.UnusedPrivateConstructor)) return;
MethodBinding constructor = constructorDecl.binding;
this.handle(
@@ -8626,7 +8649,7 @@ public void unusedPrivateField(FieldDeclaration fieldDecl) {
}
}
}
- if (excludeDueToAnnotation(fieldDecl.annotations)) return;
+ if (excludeDueToAnnotation(fieldDecl.annotations, IProblem.UnusedPrivateField)) return;
this.handle(
IProblem.UnusedPrivateField,
new String[] {
@@ -8680,7 +8703,7 @@ public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
&& CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) {
return;
}
- if (excludeDueToAnnotation(methodDecl.annotations)) return;
+ if (excludeDueToAnnotation(methodDecl.annotations, IProblem.UnusedPrivateMethod)) return;
this.handle(
IProblem.UnusedPrivateMethod,
@@ -8702,9 +8725,10 @@ public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
/**
* Returns true if a private member should not be warned as unused if
* annotated with a non-standard annotation.
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437
+ * https://bugs.eclipse.org/365437
+ * https://bugs.eclipse.org/376590
*/
-private boolean excludeDueToAnnotation(Annotation[] annotations) {
+private boolean excludeDueToAnnotation(Annotation[] annotations, int problemId) {
int annotationsLen = 0;
if (annotations != null) {
annotationsLen = annotations.length;
@@ -8723,6 +8747,11 @@ private boolean excludeDueToAnnotation(Annotation[] annotations) {
case TypeIds.T_ConfiguredAnnotationNullable:
case TypeIds.T_ConfiguredAnnotationNonNullByDefault:
break;
+ case TypeIds.T_JavaxInjectInject:
+ case TypeIds.T_ComGoogleInjectInject:
+ if (problemId != IProblem.UnusedPrivateField)
+ return true; // @Inject on method/ctor does constitute a relevant use, just on fields it doesn't
+ break;
default:
// non-standard annotation found, don't warn
return true;
@@ -8739,7 +8768,7 @@ public void unusedPrivateType(TypeDeclaration typeDecl) {
// SH}
int severity = computeSeverity(IProblem.UnusedPrivateType);
if (severity == ProblemSeverities.Ignore) return;
- if (excludeDueToAnnotation(typeDecl.annotations)) return;
+ if (excludeDueToAnnotation(typeDecl.annotations, IProblem.UnusedPrivateType)) return;
ReferenceBinding type = typeDecl.binding;
this.handle(
IProblem.UnusedPrivateType,
@@ -12877,6 +12906,22 @@ public void messageSendRedundantCheckOnNonNull(MethodBinding method, ASTNode loc
location.sourceStart,
location.sourceEnd);
}
+public void expressionNullReference(ASTNode location) {
+ this.handle(
+ IProblem.NullExpressionReference,
+ NoArgument,
+ NoArgument,
+ location.sourceStart,
+ location.sourceEnd);
+}
+public void expressionPotentialNullReference(ASTNode location) {
+ this.handle(
+ IProblem.PotentialNullExpressionReference,
+ NoArgument,
+ NoArgument,
+ location.sourceStart,
+ location.sourceEnd);
+}
public void cannotImplementIncompatibleNullness(MethodBinding currentMethod, MethodBinding inheritedMethod) {
int sourceStart = 0, sourceEnd = 0;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index 33aa94105..3157cd59f 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -23,6 +23,7 @@
# bug 393719 - [compiler] inconsistent warnings on iteration variables
# bug 331649 - [compiler][null] consider null annotations for fields
# bug 382789 - [compiler][null] warn when syntactically-nonnull expression is compared against null
+# bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
###############################################################################
0 = {0}
1 = super cannot be used in java.lang.Object
@@ -406,7 +407,8 @@
456 = instanceof always yields false: The variable {0} can only be null at this location
457 = Redundant null check: The variable {0} cannot be null at this location
458 = Null comparison always yields false: The variable {0} cannot be null at this location
-
+459 = Potential null pointer access: This expression of type {0} may be null but requires auto-unboxing
+461 = Null pointer access: This expression of type {0} is null but requires auto-unboxing
460 = Empty block should be documented
### DOC
@@ -600,6 +602,8 @@
### NULL ANALYSIS FOR OTHER EXPRESSIONS
670 = Null comparison always yields false: this expression cannot be null
671 = Redundant null check: this expression cannot be null
+672 = Null pointer access: This expression can only be null
+673 = Potential null pointer access: This expression may be null
### CORRUPTED BINARIES
700 = The class file {0} contains a signature ''{1}'' ill-formed at position {2}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java
index 84fb0ca66..7542cacc1 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -1730,6 +1730,8 @@ class DefaultBindingResolver extends BindingResolver {
if (node instanceof ParameterizedQualifiedTypeReference) {
ParameterizedQualifiedTypeReference typeReference = (ParameterizedQualifiedTypeReference) node;
org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding = typeReference.resolvedType;
+ // This unlikely case is possible when for some reason binding resolution has been stopped, like duplicate type declaration (bug 376440)
+ if (typeBinding == null) return null;
if (type.isArrayType()) {
if (this.scope == null) {
return null;
diff --git a/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetThisReference.java b/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetThisReference.java
index 9bbe45a0d..5a41e10e4 100644
--- a/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetThisReference.java
+++ b/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetThisReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -7,6 +7,8 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Jesper S Moller - Contributions for
+ * Bug 378674 - "The method can be declared as static" is wrong
*******************************************************************************/
package org.eclipse.jdt.internal.eval;
@@ -54,6 +56,7 @@ public class CodeSnippetThisReference extends ThisReference implements Evaluatio
methodScope.problemReporter().errorThisSuperInStatic(this);
return false;
}
+ methodScope.resetEnclosingMethodStaticFlag();
return true;
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAccessRule.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAccessRule.java
index db57facb9..12f4e3b66 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAccessRule.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAccessRule.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -19,17 +19,19 @@ import org.eclipse.core.runtime.IPath;
* <p>
* On a given classpath entry, the access rules are considered in the order given
* when the entry was created. When a source or class file matches an access
- * rule's pattern, the access rule's kind define whether the file is considered
- * accessible, non accessible, or its access is discouraged. If the source or class
- * file doesn't match any accessible rule, it is considered accessible. A source or class
- * file that is not accessible or discouraged can still be refered to but it is tagged as being not
- * accessible - the Java builder will create a problem marker for example.
- * The severity of the marker created from a non accessible rule is controled through
+ * rule's pattern, the access rule's kind defines whether the file is considered
+ * accessible, non-accessible, or whether its access is discouraged. If the source or class
+ * file doesn't match any access rule, it is considered accessible. A source or class
+ * file that is not accessible or discouraged can still be referred to, but it is tagged as being not
+ * accessible - the Java builder will create a problem marker, for example.
+ * The severity of the marker created from a non-accessible rule is controlled through
* the {@link JavaCore#COMPILER_PB_FORBIDDEN_REFERENCE} compiler option.
- * The severity of the marker created from a discouraged rule is controled through
+ * The severity of the marker created from a discouraged rule is controlled through
* the {@link JavaCore#COMPILER_PB_DISCOURAGED_REFERENCE} compiler option.
* Note this is different from inclusion and exclusion patterns on source classpath entries,
* where a source file that is excluded is not even compiled.
+ * </p>
+ * <p>
* Files patterns look like relative file paths with wildcards and are interpreted relative
* to each entry's path.
* File patterns are case-sensitive and they can contain '**', '*' or '?' wildcards (see
@@ -40,8 +42,8 @@ import org.eclipse.core.runtime.IPath;
* <code>com/xyz/tests/MyClass.class</code> is not valid.
* </p>
* <p>
- * For example, if one of the entry path is <code>/Project/someLib.jar</code>,
- * there are no accessible rules, and there is one non accessible rule whith pattern
+ * For example, if a classpath entry path is <code>/Project/someLib.jar</code>,
+ * there are no accessible rules, and there is one non-accessible rule with pattern
* <code>com/xyz/tests/&#42;&#42;</code>, then class files
* like <code>/Project/someLib.jar/com/xyz/Foo.class</code>
* and <code>/Project/someLib.jar/com/xyz/utils/Bar.class</code> would be accessible,
@@ -49,11 +51,13 @@ import org.eclipse.core.runtime.IPath;
* and <code>/Project/someLib.jar/com/xyz/tests/quick/T2.class</code> would not be
* accessible.
* </p>
- * <p>
- * This interface is not intended to be implemented by clients.
- * </p>
*
* @since 3.1
+ *
+ * @see JavaCore#newAccessRule(IPath, int)
+ * @see IClasspathEntry#getExclusionPatterns()
+ *
+ * @noimplement This interface is not intended to be implemented by clients.
*/
public interface IAccessRule {
@@ -63,7 +67,7 @@ public interface IAccessRule {
int K_ACCESSIBLE = 0;
/**
- * Constant indicating that files matching the rule's pattern are non accessible.
+ * Constant indicating that files matching the rule's pattern are non-accessible.
*/
int K_NON_ACCESSIBLE = 1;
@@ -90,6 +94,8 @@ public interface IAccessRule {
* Returns the file pattern for this access rule.
*
* @return the file pattern for this access rule
+ *
+ * @see IClasspathEntry#getExclusionPatterns()
*/
IPath getPattern();
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAnnotatable.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAnnotatable.java
index 6e5010357..a9765a8fd 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAnnotatable.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAnnotatable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -12,11 +12,9 @@ package org.eclipse.jdt.core;
/**
* Common protocol for Java elements that can be annotated.
- * <p>
- * This interface is not intended to be implemented by clients.
- * </p>
*
* @since 3.4
+ * @noimplement This interface is not intended to be implemented by clients.
*/
public interface IAnnotatable {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAnnotation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAnnotation.java
index ce066236d..36dca8f0c 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAnnotation.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IAnnotation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -19,11 +19,9 @@ package org.eclipse.jdt.core;
* Note that annotations are not children of their declaring element.
* To get a list of the annotations use {@link IAnnotatable#getAnnotations()}.
* </p>
- * <p>
- * This interface is not intended to be implemented or extended by clients.
- * </p>
*
* @since 3.4
+ * @noimplement This interface is not intended to be implemented by clients.
*/
public interface IAnnotation extends IJavaElement, ISourceReference {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
index 63c740873..686c57032 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -125,7 +125,6 @@ import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
-
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -139,7 +138,6 @@ import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
-
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
@@ -147,7 +145,6 @@ import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.core.search.TypeNameRequestor;
-
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
@@ -4304,7 +4301,7 @@ public final class JavaCore extends Plugin {
* <p>
* The rule kind is one of {@link IAccessRule#K_ACCESSIBLE}, {@link IAccessRule#K_DISCOURAGED},
* or {@link IAccessRule#K_NON_ACCESSIBLE}, optionally combined with {@link IAccessRule#IGNORE_IF_BETTER},
- * e..g. <code>IAccessRule.K_NON_ACCESSIBLE | IAccessRule.IGNORE_IF_BETTER</code>.
+ * e.g. <code>IAccessRule.K_NON_ACCESSIBLE | IAccessRule.IGNORE_IF_BETTER</code>.
* </p>
*
* @param filePattern the file pattern this access rule should match
@@ -4313,6 +4310,8 @@ public final class JavaCore extends Plugin {
* {@link IAccessRule#IGNORE_IF_BETTER}
* @return a new access rule
* @since 3.1
+ *
+ * @see IClasspathEntry#getExclusionPatterns()
*/
public static IAccessRule newAccessRule(IPath filePattern, int kind) {
return new ClasspathAccessRule(filePattern, kind);
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMethod.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMethod.java
index 1d1fd2958..09e67fdb0 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMethod.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMethod.java
@@ -84,21 +84,51 @@ public ILocalVariable[] getParameters() throws JavaModelException {
argumentNames[j] = ("arg" + j).toCharArray(); //$NON-NLS-1$
}
}
+ int startIndex = 0;
+ try {
+ if (isConstructor()) {
+ IType declaringType = this.getDeclaringType();
+ if (declaringType.isEnum()) {
+ startIndex = 2;
+ } else if (declaringType.isMember()
+ && !Flags.isStatic(declaringType.getFlags())) {
+ startIndex = 1;
+ }
+ }
+ } catch(JavaModelException e) {
+ // ignore
+ }
for (int i= 0; i < length; i++) {
- LocalVariable localVariable = new LocalVariable(
- this,
- new String(argumentNames[i]),
- 0,
- -1,
- 0,
- -1,
- this.parameterTypes[i],
- null,
- -1,
- true);
- localVariables[i] = localVariable;
- IAnnotation[] annotations = getAnnotations(localVariable, info.getParameterAnnotations(i));
- localVariable.annotations = annotations;
+ if (i < startIndex) {
+ LocalVariable localVariable = new LocalVariable(
+ this,
+ new String(argumentNames[i]),
+ 0,
+ -1,
+ 0,
+ -1,
+ this.parameterTypes[i],
+ null,
+ -1,
+ true);
+ localVariables[i] = localVariable;
+ localVariable.annotations = Annotation.NO_ANNOTATIONS;
+ } else {
+ LocalVariable localVariable = new LocalVariable(
+ this,
+ new String(argumentNames[i]),
+ 0,
+ -1,
+ 0,
+ -1,
+ this.parameterTypes[i],
+ null,
+ -1,
+ true);
+ localVariables[i] = localVariable;
+ IAnnotation[] annotations = getAnnotations(localVariable, info.getParameterAnnotations(i - startIndex));
+ localVariable.annotations = annotations;
+ }
}
return localVariables;
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileInfo.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileInfo.java
index c59efc390..9c06306f5 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileInfo.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileInfo.java
@@ -429,8 +429,21 @@ private void generateMethodInfos(IType type, IBinaryType typeInfo, HashMap newEl
argumentNames[j] = ("arg" + j).toCharArray(); //$NON-NLS-1$
}
}
- for (int j = 0; j < max; j++) {
- IBinaryAnnotation[] parameterAnnotations = methodInfo.getParameterAnnotations(j);
+ int startIndex = 0;
+ try {
+ if (isConstructor) {
+ if (type.isEnum()) {
+ startIndex = 2;
+ } else if (type.isMember()
+ && !Flags.isStatic(type.getFlags())) {
+ startIndex = 1;
+ }
+ }
+ } catch(JavaModelException e) {
+ // ignore
+ }
+ for (int j = startIndex; j < max; j++) {
+ IBinaryAnnotation[] parameterAnnotations = methodInfo.getParameterAnnotations(j - startIndex);
if (parameterAnnotations != null) {
LocalVariable localVariable = new LocalVariable(
method,
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java
index 71d8660ed..68abebbc0 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -878,14 +878,21 @@ public abstract class JavaElement extends PlatformObject implements IJavaElement
} catch (MalformedURLException e) {
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, this));
} catch (FileNotFoundException e) {
- // ignore. see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=120559
- } catch(SocketException e) {
- // ignore. see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=247845
- } catch(UnknownHostException e) {
- // ignore. see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=247845
- } catch(ProtocolException e) {
- // ignore. see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=247845
- } catch(IOException e) {
+ // Ignore, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=120559 &
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=403036
+ } catch (SocketException e) {
+ // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=247845 &
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=400060
+ throw new JavaModelException(e, IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC);
+ } catch (UnknownHostException e) {
+ // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=247845 &
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=400060
+ throw new JavaModelException(e, IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC);
+ } catch (ProtocolException e) {
+ // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=247845 &
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=400060
+ throw new JavaModelException(e, IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC);
+ } catch (IOException e) {
throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
} finally {
if (stream != null) {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/TypeHierarchy.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/TypeHierarchy.java
index 59ad02d14..4f9ebc2af 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/TypeHierarchy.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/TypeHierarchy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -737,10 +737,14 @@ public boolean hasFineGrainChanges() {
return collector != null && collector.needsRefresh();
}
/**
- * Returns whether one of the subtypes in this hierarchy has the given simple name
- * or this type has the given simple name.
+ * Returns whether this type or one of the subtypes in this hierarchy has the
+ * same simple name as the given name.
*/
-private boolean hasSubtypeNamed(String simpleName) {
+private boolean hasSubtypeNamed(String name) {
+ int idx = -1;
+ String rawName = (idx = name.indexOf('<')) > -1 ? name.substring(0, idx) : name;
+ String simpleName = (idx = rawName.lastIndexOf('.')) > -1 ? rawName.substring(idx + 1) : rawName;
+
if (this.focusType != null && this.focusType.getElementName().equals(simpleName)) {
return true;
}
@@ -1471,11 +1475,7 @@ boolean subtypesIncludeSupertypeOf(IType type) {
if (superclassName == null) {
superclassName = "Object"; //$NON-NLS-1$
}
- int dot = -1;
- String simpleSuper = (dot = superclassName.lastIndexOf('.')) > -1 ?
- superclassName.substring(dot + 1) :
- superclassName;
- if (hasSubtypeNamed(simpleSuper)) {
+ if (hasSubtypeNamed(superclassName)) {
return true;
}
@@ -1489,12 +1489,8 @@ boolean subtypesIncludeSupertypeOf(IType type) {
return false;
}
for (int i = 0, length = interfaceNames.length; i < length; i++) {
- dot = -1;
String interfaceName = interfaceNames[i];
- String simpleInterface = (dot = interfaceName.lastIndexOf('.')) > -1 ?
- interfaceName.substring(dot) :
- interfaceName;
- if (hasSubtypeNamed(simpleInterface)) {
+ if (hasSubtypeNamed(interfaceName)) {
return true;
}
}
diff --git a/org.eclipse.jdt.core/pom.xml b/org.eclipse.jdt.core/pom.xml
index 366546298..16c9d5976 100644
--- a/org.eclipse.jdt.core/pom.xml
+++ b/org.eclipse.jdt.core/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2012 Eclipse Foundation.
+ Copyright (c) 2012, 2013 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
@@ -19,7 +19,7 @@
<groupId>eclipse.jdt.core</groupId>
<version>3.8.0-SNAPSHOT</version>
</parent>
- <groupId>eclipse.jdt.core</groupId>
+ <groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.9.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

Back to the top