Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jdt.core.tests.compiler/src')
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/JavadocCompletionParserTest.java19
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java7
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java18
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java108
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java87
5 files changed, 193 insertions, 46 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/JavadocCompletionParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/JavadocCompletionParserTest.java
index 91068fbde9..2c248093e2 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/JavadocCompletionParserTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/JavadocCompletionParserTest.java
@@ -163,6 +163,7 @@ protected void verifyCompletionOnJavadocTag(char[] tag, char[][] expectedTags, b
}
protected void verifyAllTagsCompletion() {
+ char[][] allTagsFinal =null;
char[][] allTags = {
// Block tags
TAG_AUTHOR, TAG_DEPRECATED, TAG_EXCEPTION, TAG_PARAM, TAG_RETURN, TAG_SEE, TAG_VERSION, TAG_CATEGORY,
@@ -172,6 +173,15 @@ protected void verifyAllTagsCompletion() {
TAG_LINK,
TAG_DOC_ROOT,
};
+ char[][] allTagsJava9Plus = {
+ // Block tags
+ TAG_AUTHOR, TAG_DEPRECATED, TAG_EXCEPTION, TAG_PARAM, TAG_RETURN, TAG_SEE, TAG_VERSION, TAG_CATEGORY,
+ TAG_SINCE,
+ TAG_SERIAL, TAG_SERIAL_DATA, TAG_SERIAL_FIELD , TAG_THROWS, TAG_USES, TAG_PROVIDES,
+ // Inline tags
+ TAG_LINK,
+ TAG_DOC_ROOT
+ };
char[][] additionalTags = null;
if(this.complianceLevel == ClassFileConstants.JDK1_4) {
additionalTags = new char[][] {
@@ -188,13 +198,14 @@ protected void verifyAllTagsCompletion() {
TAG_CODE, TAG_LITERAL, TAG_SYSTEM_PROPERTY
};
}
+ allTagsFinal = this.complianceLevel > ClassFileConstants.JDK1_8 ? allTagsJava9Plus : allTags;
if (additionalTags != null) {
- int length = allTags.length;
+ int length = allTagsFinal.length;
int add = additionalTags.length;
- System.arraycopy(allTags, 0, allTags = new char[length+add][], 0, length);
- System.arraycopy(additionalTags, 0, allTags, length, add);
+ System.arraycopy(allTagsFinal, 0, allTagsFinal = new char[length+add][], 0, length);
+ System.arraycopy(additionalTags, 0, allTagsFinal, length, add);
}
- verifyCompletionOnJavadocTag(null, allTags, false);
+ verifyCompletionOnJavadocTag(null, allTagsFinal, false);
}
/**
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 01f318f6a7..a60834331f 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
@@ -936,7 +936,9 @@ protected static class JavacTestOptions {
JavacBug8044196 = RUN_JAVAC ? // likely https://bugs.openjdk.java.net/browse/JDK-8044196, intermittently masked by https://bugs.openjdk.java.net/browse/JDK-8029161
new JavacHasABug(MismatchType.EclipseErrorsJavacNone, ClassFileConstants.JDK9, 0000, true) : null,
JavacBug6337964 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=112433
- new JavacHasABug(MismatchType.JavacErrorsEclipseNone, ClassFileConstants.JDK1_6, 1045/*guessed*/, true) : null;
+ new JavacHasABug(MismatchType.JavacErrorsEclipseNone, ClassFileConstants.JDK1_6, 1045/*guessed*/, true) : null,
+ JavacBug8144832 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8144832
+ new JavacHasABug(MismatchType.JavacErrorsEclipseNone, ClassFileConstants.JDK9, 0000) : null;
// bugs that have been fixed but that we've not identified
public static JavacHasABug
@@ -958,9 +960,6 @@ protected static class JavacTestOptions {
ClassFileConstants.JDK9, 0100 /* 9.0.1 or better */) : null;
// bugs that have neither been fixed nor formally identified but which outcomes are obvious enough to clear any doubts
public static JavacHasABug
- JavacGeneratesByteCodeUponWhichJavaThrowsAnException = RUN_JAVAC ?
- new JavacHasABug(
- MismatchType.StandardOutputMismatch) : null,
JavacThrowsAnException = RUN_JAVAC ? // some of these are transient - that is, depend on the system on which the test is run, aka stack overflow
new JavacHasABug(
MismatchType.JavacErrorsEclipseNone) : null,
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
index 7107d367de..1ccbeb201b 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -984,7 +984,7 @@ public void test012b(){
String logContents = Util.fileContent(logFileName);
String expectedLogContents =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
- "<!DOCTYPE compiler PUBLIC \"-//Eclipse.org//DTD Eclipse JDT 3.2.005 Compiler//EN\" \"http://www.eclipse.org/jdt/core/compiler_32_005.dtd\">\n" +
+ "<!DOCTYPE compiler PUBLIC \"-//Eclipse.org//DTD Eclipse JDT 3.2.006 Compiler//EN\" \"http://www.eclipse.org/jdt/core/compiler_32_006.dtd\">\n" +
"<compiler copyright=\"{2}\" name=\"{1}\" version=\"{3}\">\n" +
" <command_line>\n" +
" <argument value=\"---OUTPUT_DIR_PLACEHOLDER---{0}X.java\"/>\n" +
@@ -2528,13 +2528,13 @@ public void test039(){
"----------\n" +
"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/src2/Y.java (at line 4)\n" +
" X<String> x2 = new X<String>();\n" +
- " ^^^^^^^^^^^^^^^\n" +
- "Discouraged access: The constructor \'X<String>()\' is not API (restriction on classpath entry \'---OUTPUT_DIR_PLACEHOLDER---/bin1\')\n" +
+ " ^\n" +
+ "Discouraged access: The type \'X<String>\' is not API (restriction on classpath entry \'---OUTPUT_DIR_PLACEHOLDER---/bin1\')\n" +
"----------\n" +
"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/src2/Y.java (at line 4)\n" +
" X<String> x2 = new X<String>();\n" +
" ^\n" +
- "Discouraged access: The type \'X<String>\' is not API (restriction on classpath entry \'---OUTPUT_DIR_PLACEHOLDER---/bin1\')\n" +
+ "Discouraged access: The constructor \'X<String>()\' is not API (restriction on classpath entry \'---OUTPUT_DIR_PLACEHOLDER---/bin1\')\n" +
"----------\n" +
"5 problems (5 warnings)\n",
false);
@@ -5332,17 +5332,17 @@ public void test148_access_restrictions(){
"----------\n" +
"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
" ko = new KO();\n" +
- " ^^^^^^^^\n" +
- "Access restriction: The constructor \'KO()\' is not API (restriction on classpath entry \'---OUTPUT_DIR_PLACEHOLDER---\')\n" +
+ " ^^\n" +
+ "Access restriction: The type \'KO\' is not API (restriction on classpath entry \'---OUTPUT_DIR_PLACEHOLDER---\')\n" +
"----------\n" +
"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
" ko = new KO();\n" +
" ^^\n" +
- "Access restriction: The type \'KO\' is not API (restriction on classpath entry \'---OUTPUT_DIR_PLACEHOLDER---\')\n" +
+ "Access restriction: The constructor \'KO()\' is not API (restriction on classpath entry \'---OUTPUT_DIR_PLACEHOLDER---\')\n" +
"----------\n" +
"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 6)\n" +
" ko.bar();\n" +
- " ^^^^^^^^\n" +
+ " ^^^\n" +
"Access restriction: The method \'KO.bar()\' is not API (restriction on classpath entry \'---OUTPUT_DIR_PLACEHOLDER---\')\n" +
"----------\n" +
"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 7)\n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java
index e723cdbad6..5deac455aa 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2017 IBM Corporation and others.
+ * Copyright (c) 2003, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -21,6 +21,7 @@ import java.util.Map;
import junit.framework.Test;
import org.eclipse.jdt.core.ToolFactory;
+import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.Excuse;
import org.eclipse.jdt.core.tests.util.Util;
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
@@ -1497,7 +1498,7 @@ public void test036() {
"no base" /* expected output string */,
"" /* expected error string */,
// javac options
- JavacTestOptions.JavacHasABug.JavacGeneratesByteCodeUponWhichJavaThrowsAnException /* javac test options */);
+ JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */);
}
public void test037() {
this.runNegativeTest(
@@ -1828,7 +1829,8 @@ public void test048() {
public void test049() {
CompilerOptions options = new CompilerOptions(getCompilerOptions());
if (options.sourceLevel < ClassFileConstants.JDK1_5) return;
- this.runNegativeTest(
+ Runner runner = new Runner();
+ runner.testFiles =
new String[] {
"A.java",
"public class A {\n" +
@@ -1844,14 +1846,18 @@ public void test049() {
" class Member2<U> extends Other<U>.Member {\n" +
" }\n" +
"}\n"
- },
+ };
+ runner.expectedCompilerLog =
"----------\n" +
"1. WARNING in A.java (at line 3)\n" +
" Other<?>.Member m = (Other<?>.Member) om2;\n" +
" ^^^^^^^^^^^^^^^^^^^^^\n" +
"Unnecessary cast from Other2<?>.Member2<capture#1-of ?> to Other<?>.Member\n" +
- "----------\n"
- );
+ "----------\n";
+ runner.javacTestOptions =
+ Excuse.EclipseHasSomeMoreWarnings; // javac is inconsistent: accepting both assignments, not issuing a warning though in simpler cases it does
+ // note that javac 1.6 doesn't even accept the syntax of this cast
+ runner.runWarningTest();
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302919
public void test050() {
@@ -2521,7 +2527,9 @@ public void testBug428274() {
public void testBug428274b() {
if (this.complianceLevel < ClassFileConstants.JDK1_5)
return; // uses generics
- String source =
+ Runner runner = new Runner();
+ runner.testFiles = new String[] {
+ "Junk4.java",
"public class Junk4<T> {\n" +
" void setValue(T n) {\n" +
" int rounded = (int) Math.round((double) n);\n" +
@@ -2532,26 +2540,22 @@ public void testBug428274b() {
" j.setValue(Double.valueOf(3.3));\n" +
" j.setValue(Double.valueOf(3.7));\n" +
" }\n" +
- "}\n";
+ "}\n"
+ };
if (this.complianceLevel < ClassFileConstants.JDK1_7) {
- runNegativeTest(
- new String[] {
- "Junk4.java",
- source
- },
+ runner.expectedCompilerLog =
"----------\n" +
"1. ERROR in Junk4.java (at line 3)\n" +
" int rounded = (int) Math.round((double) n);\n" +
" ^^^^^^^^^^\n" +
"Cannot cast from T to double\n" +
- "----------\n");
+ "----------\n";
+ runner.runNegativeTest();
} else {
- runConformTest(
- new String[] {
- "Junk4.java",
- source
- },
- "3\n4");
+ runner.expectedOutputString =
+ "3\n4";
+ runner.javacTestOptions = JavacTestOptions.JavacHasABug.JavacBug8144832;
+ runner.runConformTest();
}
}
// note: spec allows all reference types, but neither javac nor common sense accept arrays :)
@@ -3232,9 +3236,10 @@ public void test461706() {
public void test461706a() {
if (this.complianceLevel < ClassFileConstants.JDK1_8)
return;
- Map customOptions = getCompilerOptions();
- customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR);
- this.runNegativeTest(
+ Runner runner = new Runner();
+ runner.customOptions = getCompilerOptions();
+ runner.customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING);
+ runner.testFiles =
new String[] {
"Bug.java",
"import java.util.ArrayList;\n" +
@@ -3261,16 +3266,15 @@ public void test461706a() {
" .orElse(ICondition.TRUE);\n" +
" }\n" +
"}"
- },
+ };
+ runner.expectedCompilerLog =
"----------\n" +
- "1. ERROR in Bug.java (at line 20)\n" +
+ "1. WARNING in Bug.java (at line 20)\n" +
" .map(x -> (ICondition)x)\n" +
" ^^^^^^^^^^^^^\n" +
"Unnecessary cast from Bug.ICondition to Bug.ICondition\n" +
- "----------\n",
- null,
- true,
- customOptions);
+ "----------\n";
+ runner.runWarningTest();
}
public void testAnonymous_bug520727() {
String[] source = {
@@ -3297,6 +3301,52 @@ public void testAnonymous_bug520727() {
runConformTest(source,"");
}
}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=543727 False positive "Unnecessary cast"
+public void test543727() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_7)
+ return;
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR);
+ this.runConformTest(
+ new String[] {
+ "Bug.java",
+ "import java.util.ArrayList;\n" +
+ "import java.util.List;\n" +
+ "public class Bug {\n" +
+ " public static void main(String[] args) {\n" +
+ " List<Comparable<?>> vector = new ArrayList<>();\n" +
+ " vector.add(0);\n" +
+ " if (vector.get(0) == (Integer)0) {\n" +
+ " System.out.print(\"SUCCESS\");\n" +
+ " }\n" +
+ " }" +
+ "}\n",
+ },
+ "SUCCESS");
+}
+public void test543727_notequals() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_7)
+ return;
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR);
+ this.runConformTest(
+ new String[] {
+ "Bug.java",
+ "import java.util.ArrayList;\n" +
+ "import java.util.List;\n" +
+ "public class Bug {\n" +
+ " public static void main(String[] args) {\n" +
+ " List<Comparable<?>> vector = new ArrayList<>();\n" +
+ " vector.add(0);\n" +
+ " if (vector.get(0) != (Integer)1) {\n" +
+ " System.out.print(\"SUCCESS\");\n" +
+ " }\n" +
+ " }" +
+ "}\n",
+ },
+ "SUCCESS");
+}
+
public static Class testClass() {
return CastTest.class;
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
index 1979b4bbdd..1504327072 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
@@ -9485,4 +9485,91 @@ public void testBug508834_comment0() {
};
runner.runConformTest();
}
+ public void testBug540846() {
+ Runner runner = new Runner();
+ runner.testFiles = new String[] {
+ "Test.java",
+ "import java.util.*;\n" +
+ "import java.util.stream.*;\n" +
+ "import java.math.*;\n" +
+ "\n" +
+ "public class Test {\n" +
+ " private List<Object> getRowValues(Map<String, BigDecimal> record, Stream<String> factors) {\n" +
+ " return Stream.concat(\n" +
+ " factors.map(f -> {\n" +
+ " if (f.equals(\"x\")) {\n" +
+ " return record.get(f);\n" +
+ " } else {\n" +
+ " return \"NM\";\n" +
+ " }\n" +
+ " }),\n" +
+ " Stream.of(BigDecimal.ONE)\n" +
+ " )\n" +
+ " .map(v -> (v instanceof BigDecimal) ? ((BigDecimal) v).setScale(10, BigDecimal.ROUND_HALF_UP) : v)\n" +
+ " .collect(Collectors.toList());\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.runConformTest();
+ }
+ public void testBug538192() {
+ Runner runner = new Runner();
+ runner.testFiles = new String[] {
+ "Test.java",
+ "import java.util.*;\n" +
+ "import java.util.function.Function;\n" +
+ "interface ListFunc<T> extends Function<List<String>, T> {}\n" +
+ "interface MapFunc<T> extends Function<Map<String,String>, T> {}\n" +
+ "class DTT {\n" +
+ " public <T> DTT(Class<T> c, ListFunc<T> f) {}\n" +
+ " public <T> DTT(Class<T> c, MapFunc<T> f) {} \n" +
+ "}\n" +
+ "public class Test {\n" +
+ " void test() {\n" +
+ " new DTT(Integer.class, (Map<String, String> row) -> Integer.valueOf(0));\n" +
+ " }\n" +
+ "}\n"
+ };
+ runner.runConformTest();
+ }
+ public void testBug536860() {
+ runConformTest(
+ new String[] {
+ "Snippet.java",
+ "import java.io.IOException;\n" +
+ "import java.io.InputStream;\n" +
+ "import java.nio.file.Path;\n" +
+ "import java.util.Map;\n" +
+ "import java.util.concurrent.Callable;\n" +
+ "import java.util.function.Function;\n" +
+ "\n" +
+ "interface EntityReader<T, S> { }\n" +
+ "class ExtraIOUtils {\n" +
+ " public static Callable<InputStream> getInputStreamProvider() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "public class Snippet {\n" +
+ " public <T> EntityReader<T, Path> createEntityReader(\n" +
+ " Function<? super String, ? extends String> colNameMapper,\n" +
+ " Function<? super String[], ? extends T> instantiator,\n" +
+ " Map<String, ?> runtimeValues)\n" +
+ " throws IOException {\n" +
+ " EntityReader<T, ?> streamReader =\n" +
+ " createEntityStreamReader(\n" +
+ " ExtraIOUtils.getInputStreamProvider(),\n" +
+ " colNameMapper, instantiator, runtimeValues);\n" +
+ " return null;\n" +
+ " }\n" +
+ " public <T> EntityReader<T, Callable<InputStream>> createEntityStreamReader(\n" +
+ " Callable<InputStream> streamProvider,\n" +
+ " Function<? super String, ? extends String> colNameMapper, Function<? super String[], ? extends T> instantiator,\n" +
+ " Map<String, ?> runtimeValues)\n" +
+ " throws IOException {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ });
+ }
}

Back to the top