diff options
author | Olivier Thomann | 2011-07-28 17:07:54 +0000 |
---|---|---|
committer | Olivier Thomann | 2011-07-28 17:07:54 +0000 |
commit | 699cc351076b7c5897a886d674772d111233f0a3 (patch) | |
tree | d0b734acb0677e43d77e712f057e6d4c6b66d468 /org.eclipse.jdt.core.tests.compiler | |
parent | b48948c440f4082a22e31c203db0c29a35ec4b75 (diff) | |
download | eclipse.jdt.core-699cc351076b7c5897a886d674772d111233f0a3.tar.gz eclipse.jdt.core-699cc351076b7c5897a886d674772d111233f0a3.tar.xz eclipse.jdt.core-699cc351076b7c5897a886d674772d111233f0a3.zip |
HEAD - merge Java 7 implementation in HEAD stream
Diffstat (limited to 'org.eclipse.jdt.core.tests.compiler')
46 files changed, 14834 insertions, 894 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF index 283b25687d..d89db69661 100644 --- a/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jdt.core.tests.compiler -Bundle-Version: 3.4.0.qualifier +Bundle-Version: 3.8.0.qualifier Bundle-ClassPath: jdtcoretestscompiler.jar Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java index 2aa474c63a..fa12d014a4 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java @@ -4,7 +4,7 @@ * 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 *******************************************************************************/ @@ -13,6 +13,7 @@ package org.eclipse.jdt.core.tests.compiler.parser; import junit.framework.Test; import org.eclipse.jdt.internal.codeassist.complete.InvalidCursorLocation; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; public class CompletionParserTest extends AbstractCompletionTest { public CompletionParserTest(String testName) { @@ -1577,11 +1578,12 @@ public void testEA_1() { " public EA() {\n" + " }\n" + " void foo() {\n" + - " try \n" + + " try\n" + " {\n" + " throw new Error();\n" + " }\n" + - " catch (<CompleteOnException:E> ) {\n" + + " catch (<CompleteOnException:E> )\n" + + " {\n" + " }\n" + " }\n" + "}\n"; @@ -8688,4 +8690,311 @@ public void testBug310423(){ expectedReplacedSource, testName); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338789 +public void testBug338789(){ + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + String str = + "public class Test {\n" + + " public void throwing() throws IZZBException, IZZException {}\n" + + " public void foo() {\n" + + " try {\n" + + " throwing();\n" + + " }\n" + + " catch (IZZException | IZZ) {\n" + + " bar();\n" + + " }\n" + + " }" + + "}\n" + + "class IZZAException extends Exception {\n" + + "}\n" + + "class IZZBException extends Exception {\n" + + "}\n" + + "class IZZException extends Exception {\n" + + "}\n"; + + String testName = "<complete on multi-catch block exception type declaration>"; + String completeBehind = "IZZException | IZZ"; + String expectedCompletionNodeToString = "<CompleteOnException:IZZ>"; + String completionIdentifier = "IZZ"; + String expectedReplacedSource = "IZZ"; + String expectedUnitDisplayString = + "public class Test {\n" + + " public Test() {\n" + + " }\n" + + " public void throwing() throws IZZBException, IZZException {\n" + + " }\n" + + " public void foo() {\n" + + " try\n" + + " {\n" + + " throwing();\n" + + " }\n" + + " catch (IZZException | <CompleteOnException:IZZ> )\n" + + " {\n" + + " }\n" + + " }\n" + + "}\n" + + "class IZZAException extends Exception {\n" + + " IZZAException() {\n" + + " }\n" + + "}\n" + + "class IZZBException extends Exception {\n" + + " IZZBException() {\n" + + " }\n" + + "}\n" + + "class IZZException extends Exception {\n" + + " IZZException() {\n" + + " }\n" + + "}\n"; + + int cursorLocation = str.indexOf("IZZException | IZZ") + completeBehind.length() - 1; + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338789 +// Qualified assist type reference +public void testBug338789b(){ + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + String str = + "public class Test {\n" + + " public void throwing() throws java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException {}\n" + + " public void foo() {\n" + + " try {\n" + + " throwing();\n" + + " }\n" + + " catch (java.lang.IllegalArgumentException | java.lang.I) {\n" + + " bar();\n" + + " }\n" + + " }" + + "}\n"; + + String testName = "<complete on multi-catch block exception type declaration qualified>"; + String completeBehind = "java.lang.IllegalArgumentException | java.lang.I"; + String expectedCompletionNodeToString = "<CompleteOnException:java.lang.I>"; + String completionIdentifier = "I"; + String expectedReplacedSource = "java.lang.I"; + String expectedUnitDisplayString = + "public class Test {\n" + + " public Test() {\n" + + " }\n" + + " public void throwing() throws java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException {\n" + + " }\n" + + " public void foo() {\n" + + " try\n" + + " {\n" + + " throwing();\n" + + " }\n" + + " catch (java.lang.IllegalArgumentException | <CompleteOnException:java.lang.I> )\n" + + " {\n" + + " }\n" + + " }\n" + + "}\n"; + + int cursorLocation = str.indexOf("java.lang.IllegalArgumentException | java.lang.I") + completeBehind.length() - 1; + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=343637 +// Check that the whole union type ref is part of the completion node parent +public void testBug343637(){ + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + String str = + "public class Test {\n" + + " public void throwing() throws java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException, java.lang.IOException {}\n" + + " public void foo() {\n" + + " try {\n" + + " throwing();\n" + + " }\n" + + " catch (java.lang.IOException e){}\n" + + " catch (java.lang.IllegalArgumentException | java.lang.I) {\n" + + " bar();\n" + + " }\n" + + " }" + + "}\n"; + + String testName = "<complete on multi-catch block exception type declaration qualified>"; + String completeBehind = "java.lang.IllegalArgumentException | java.lang.I"; + String expectedCompletionNodeToString = "<CompleteOnException:java.lang.I>"; + String completionIdentifier = "I"; + String expectedReplacedSource = "java.lang.I"; + String expectedUnitDisplayString = + "public class Test {\n" + + " public Test() {\n" + + " }\n" + + " public void throwing() throws java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException, java.lang.IOException {\n" + + " }\n" + + " public void foo() {\n" + + " try\n" + + " {\n" + + " throwing();\n" + + " }\n" + + " catch (java.lang.IOException e)\n" + + " {\n" + + " }\n" + + " catch (java.lang.IllegalArgumentException | <CompleteOnException:java.lang.I> )\n" + + " {\n" + + " }\n" + + " }\n" + + "}\n"; + + int cursorLocation = str.indexOf("java.lang.IllegalArgumentException | java.lang.I") + completeBehind.length() - 1; + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 +public void testBug346454(){ + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + String str = + "public class Test<T> {\n" + + " public void foo() {\n" + + " Test<String> t = new Test<>()\n" + + " }" + + "}\n"; + + String testName = "<complete after diamond type>"; + String completeBehind = "new Test<>("; + String expectedCompletionNodeToString = "<CompleteOnAllocationExpression:new Test<>()>"; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class Test<T> {\n" + + " public Test() {\n" + + " }\n" + + " public void foo() {\n" + + " Test<String> t = <CompleteOnAllocationExpression:new Test<>()>;\n" + + " }\n" + + "}\n"; + + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454 +public void testBug346454b(){ + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + String str = + "public class Test<T> {\n" + + " public class T2<Z>{}\n" + + " public void foo() {\n" + + " Test<String>.T2<String> t = new Test<>().new T2<>()\n" + + " }" + + "}\n"; + + String testName = "<complete after diamond type>"; + String completeBehind = "new Test<>().new T2<>("; + String expectedCompletionNodeToString = "<CompleteOnQualifiedAllocationExpression:new Test<>().new T2<>()>"; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class Test<T> {\n" + + " public class T2<Z> {\n" + + " public T2() {\n" + + " }\n" + + " }\n" + + " public Test() {\n" + + " }\n" + + " public void foo() {\n" + + " Test<String>.T2<String> t = <CompleteOnQualifiedAllocationExpression:new Test<>().new T2<>()>;\n" + + " }\n" + + "}\n"; + + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346415 +// To make sure that all catch blocks before the one in which we're invoking assist are avaiable in the ast. +public void testBug346415(){ + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + String str = + "public class Test {\n" + + " public void throwing() throws java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException, java.lang.IOException {}\n" + + " public void foo() {\n" + + " try {\n" + + " throwing();\n" + + " }\n" + + " catch (java.lang.IOException e){\n" + + " } catch (java.lang.IllegalArgumentException e){\n" + + " } catch (/*propose*/) {\n" + + " }\n" + + " }\n" + + "}\n"; + + String testName = "<complete on third catch block>"; + String completeBehind = "catch (/*propose*/"; + String expectedCompletionNodeToString = "<CompleteOnException:>"; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class Test {\n" + + " public Test() {\n" + + " }\n" + + " public void throwing() throws java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException, java.lang.IOException {\n" + + " }\n" + + " public void foo() {\n" + + " try\n" + + " {\n" + + " throwing();\n" + + " }\n" + + " catch (java.lang.IOException e)\n" + + " {\n" + + " }\n" + + " catch (java.lang.IllegalArgumentException e)\n" + + " {\n" + + " }\n" + + " catch (<CompleteOnException:> )\n" + + " {\n" + + " }\n" + + " }\n" + + "}\n"; + + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest2.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest2.java index 5d1a92bc74..81700ccab1 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest2.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest2.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 *******************************************************************************/ @@ -11068,13 +11068,15 @@ public void test0167_Method() { int cursorLocation = str.lastIndexOf("IZZ") + completeBehind.length() - 1; String expectedCompletionNodeToString = "<CompleteOnException:IZZ>"; String expectedParentNodeToString = - "try \n" + + "try\n" + " {\n" + " throwing();\n" + " }\n" + - "catch (IllegalAccessException e) {\n" + + "catch (IllegalAccessException e)\n" + + " {\n" + " }\n" + - "catch (<CompleteOnException:IZZ> ) {\n" + + "catch (<CompleteOnException:IZZ> )\n" + + " {\n"+ " }"; String completionIdentifier = "IZZ"; String expectedReplacedSource = "IZZ"; @@ -11083,13 +11085,15 @@ public void test0167_Method() { " public X() {\n" + " }\n" + " public boolean foo() {\n" + - " try \n" + + " try\n" + " {\n" + " throwing();\n" + " }\n" + - " catch (IllegalAccessException e) {\n" + + " catch (IllegalAccessException e)\n" + + " {\n" + " }\n" + - " catch (<CompleteOnException:IZZ> ) {\n" + + " catch (<CompleteOnException:IZZ> )\n" + + " {\n" + " }\n" + " }\n" + "}\n"; @@ -11164,13 +11168,15 @@ public void test0168_Method() { int cursorLocation = str.lastIndexOf("IZZ") + completeBehind.length() - 1; String expectedCompletionNodeToString = "<CompleteOnException:IZZ>"; String expectedParentNodeToString = - "try \n" + + "try\n" + " {\n" + " throwing();\n" + " }\n" + - "catch (IllegalAccessException e) {\n" + + "catch (IllegalAccessException e)\n" + + " {\n" + " }\n" + - "catch (<CompleteOnException:IZZ> ) {\n" + + "catch (<CompleteOnException:IZZ> )\n" + + " {\n"+ " }"; String completionIdentifier = "IZZ"; String expectedReplacedSource = "IZZ"; @@ -11179,13 +11185,15 @@ public void test0168_Method() { " public X() {\n" + " }\n" + " public boolean foo() {\n" + - " try \n" + + " try\n" + " {\n" + " throwing();\n" + " }\n" + - " catch (IllegalAccessException e) {\n" + + " catch (IllegalAccessException e)\n" + + " {\n" + " }\n" + - " catch (<CompleteOnException:IZZ> ) {\n" + + " catch (<CompleteOnException:IZZ> )\n" + + " {\n" + " }\n" + " }\n" + "}\n"; @@ -11424,11 +11432,12 @@ public void test0171_Method() { int cursorLocation = str.lastIndexOf("IZZ") + completeBehind.length() - 1; String expectedCompletionNodeToString = "<CompleteOnException:IZZ>"; String expectedParentNodeToString = - "try \n" + + "try\n" + " {\n" + " throwing();\n" + " }\n" + - "catch (<CompleteOnException:IZZ> ) {\n" + + "catch (<CompleteOnException:IZZ> )\n" + + " {\n"+ " }" ; String completionIdentifier = "IZZ"; @@ -11438,11 +11447,12 @@ public void test0171_Method() { " public X() {\n" + " }\n" + " public boolean foo() {\n" + - " try \n" + + " try\n" + " {\n" + " throwing();\n" + " }\n" + - " catch (<CompleteOnException:IZZ> ) {\n" + + " catch (<CompleteOnException:IZZ> )\n" + + " {\n"+ " }\n" + " }\n" + "}\n"; diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java index 585baadcc3..8a4416c1c0 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java @@ -45,6 +45,22 @@ public void runComplianceParserTest( this.runNegativeTest(testFiles, expected15ProblemLog); } } +public void runComplianceParserTest( + String[] testFiles, + String expected13ProblemLog, + String expected14ProblemLog, + String expected15ProblemLog, + String expected17ProblemLog){ + if(this.complianceLevel == ClassFileConstants.JDK1_3) { + this.runNegativeTest(testFiles, expected13ProblemLog); + } else if(this.complianceLevel == ClassFileConstants.JDK1_4) { + this.runNegativeTest(testFiles, expected14ProblemLog); + } else if(this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest(testFiles, expected15ProblemLog); + } else { + this.runNegativeTest(testFiles, expected17ProblemLog); + } + } public void test0001() { String[] testFiles = new String[] { "X.java", @@ -58,7 +74,7 @@ public void test0001() { "1. ERROR in X.java (at line 1)\n" + " import static aaa.BBB.*;\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, static imports are only available if source level is 1.5\n" + + "Syntax error, static imports are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 1)\n" + " import static aaa.BBB.*;\n" + @@ -96,7 +112,7 @@ public void test0002() { "1. ERROR in X.java (at line 1)\n" + " import static aaa.BBB.CCC;\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, static imports are only available if source level is 1.5\n" + + "Syntax error, static imports are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 1)\n" + " import static aaa.BBB.CCC;\n" + @@ -164,7 +180,7 @@ public void test0004() { "1. ERROR in X.java (at line 3)\n" + " for(String o: c) {\n" + " ^^^^^^^^^^^\n" + - "Syntax error, \'for each\' statements are only available if source level is 1.5\n" + + "Syntax error, \'for each\' statements are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 3)\n" + " for(String o: c) {\n" + @@ -203,7 +219,7 @@ public void test0005() { "1. ERROR in X.java (at line 2)\n" + " void foo(Z ... arg){\n" + " ^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 2)\n" + " void foo(Z ... arg){\n" + @@ -240,7 +256,7 @@ public void test0006() { "1. ERROR in X.java (at line 1)\n" + " public class X <T1 extends String, T2> extends Y {\n" + " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 1)\n" + " public class X <T1 extends String, T2> extends Y {\n" + @@ -282,7 +298,7 @@ public void test0007() { "1. ERROR in X.java (at line 1)\n" + " public interface X <T1 extends String, T2> extends Y {\n" + " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 1)\n" + " public interface X <T1 extends String, T2> extends Y {\n" + @@ -326,7 +342,7 @@ public void test0008() { "1. ERROR in X.java (at line 2)\n" + " public <T1 extends String, T2> int foo(){\n" + " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n"; String expected14ProblemLog = expected13ProblemLog; @@ -365,7 +381,7 @@ public void test0009() { "1. ERROR in X.java (at line 2)\n" + " public <T1 extends String, T2> X(){\n" + " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n"; String expected15ProblemLog = @@ -405,7 +421,7 @@ public void test0010() { "2. ERROR in X.java (at line 2)\n" + " Z<Y1, Y2> var;\n" + " ^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 2)\n" + " Z<Y1, Y2> var;\n" + @@ -460,7 +476,7 @@ public void test0011() { "1. ERROR in X.java (at line 3)\n" + " <Y1, Y2>this(null);\n" + " ^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 3)\n" + " <Y1, Y2>this(null);\n" + @@ -550,7 +566,7 @@ public void test0013() { "1. ERROR in X.java (at line 1)\n" + " import static aaa.*\n" + " ^^^^^^^^^^^^^^^^^\n" + - "Syntax error, static imports are only available if source level is 1.5\n" + + "Syntax error, static imports are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 1)\n" + " import static aaa.*\n" + @@ -635,7 +651,7 @@ public void test0015() { "1. ERROR in X.java (at line 3)\n" + " for(String o: c) {\n" + " ^^^^^^^^^^^\n" + - "Syntax error, \'for each\' statements are only available if source level is 1.5\n" + + "Syntax error, \'for each\' statements are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " #\n" + @@ -675,7 +691,7 @@ public void test0016() { "1. ERROR in X.java (at line 2)\n" + " void foo(Z ... arg){\n" + " ^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 2)\n" + " void foo(Z ... arg){\n" + @@ -723,7 +739,7 @@ public void test0017() { "1. ERROR in X.java (at line 1)\n" + " public class X <T1 extends String, T2> extends Y {\n" + " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 1)\n" + " public class X <T1 extends String, T2> extends Y {\n" + @@ -778,7 +794,7 @@ public void test0018() { "1. ERROR in X.java (at line 2)\n" + " public <T1 extends String, T2> int foo(){\n" + " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " #\n" + @@ -827,7 +843,7 @@ public void test0019() { "2. ERROR in X.java (at line 2)\n" + " Z<Y1, Y2> var;\n" + " ^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 2)\n" + " Z<Y1, Y2> var;\n" + @@ -984,7 +1000,7 @@ public void test0022() { "1. ERROR in X.java (at line 1)\n" + " import static aaa.*.*;\n" + " ^^^^^^^^^^^^^^^^^\n" + - "Syntax error, static imports are only available if source level is 1.5\n" + + "Syntax error, static imports are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 1)\n" + " import static aaa.*.*;\n" + @@ -1397,7 +1413,7 @@ public void test0031() { "2. ERROR in X.java (at line 2)\n" + " void foo(int ... aaa bbb){\n" + " ^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 2)\n" + " void foo(int ... aaa bbb){\n" + @@ -1628,7 +1644,7 @@ public void test0036() { "1. ERROR in X.java (at line 2)\n" + " public <T1 extends String, T2> foo(){\n" + " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 2)\n" + " public <T1 extends String, T2> foo(){\n" + @@ -2020,7 +2036,7 @@ public void test0044() { "1. ERROR in X.java (at line 2)\n" + " public <T> X(T t){\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 5)\n" + " }\n" + @@ -2030,12 +2046,12 @@ public void test0044() { "3. ERROR in X.java (at line 9)\n" + " <String>super(\"SUCCESS\");\n" + " ^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in X.java (at line 9)\n" + " <String>super(\"SUCCESS\");\n" + " ^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"; String expected14ProblemLog = expected13ProblemLog; @@ -2106,7 +2122,7 @@ public void test0046() { "1. ERROR in X.java (at line 1)\n" + " public @interface X {\n" + " ^\n" + - "Syntax error, annotation declarations are only available if source level is 1.5\n" + + "Syntax error, annotation declarations are only available if source level is 1.5 or greater\n" + "----------\n"; String expected14ProblemLog = expected13ProblemLog; @@ -2137,13 +2153,13 @@ public void test0047() { "1. ERROR in A.java (at line 1)\n" + " public @interface A {}\n" + " ^\n" + - "Syntax error, annotation declarations are only available if source level is 1.5\n" + + "Syntax error, annotation declarations are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in X.java (at line 1)\n" + " @A public class X {\n" + " ^^\n" + - "Syntax error, annotations are only available if source level is 1.5\n" + + "Syntax error, annotations are only available if source level is 1.5 or greater\n" + "----------\n"; String expected14ProblemLog = expected13ProblemLog; @@ -2171,7 +2187,7 @@ public void test0048() { "1. ERROR in X.java (at line 2)\n" + " void foo(X ... arg[]){\n" + " ^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n"; String expected14ProblemLog = expected13ProblemLog; @@ -2208,7 +2224,7 @@ public void test0049() { "1. ERROR in X.java (at line 1)\n" + " @interface MyAnn {\n" + " ^^^^^\n" + - "Syntax error, annotation declarations are only available if source level is 1.5\n" + + "Syntax error, annotation declarations are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 6)\n" + " public @MyAnn(\"\",\"\") class Test { \n" + @@ -2266,7 +2282,7 @@ public void test0050() { "1. ERROR in X.java (at line 2)\n" + " void foo(List<String>... args) {}\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 2)\n" + " void foo(List<String>... args) {}\n" + @@ -2276,7 +2292,7 @@ public void test0050() { "3. ERROR in X.java (at line 2)\n" + " void foo(List<String>... args) {}\n" + " ^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"; String expected14ProblemLog = expected13ProblemLog; @@ -2288,12 +2304,25 @@ public void test0050() { " ^^^^\n" + "List cannot be resolved to a type\n" + "----------\n"; + String expected17ProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(List<String>... args) {}\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " void foo(List<String>... args) {}\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter args\n" + + "----------\n"; runComplianceParserTest( testFiles, expected13ProblemLog, expected14ProblemLog, - expected15ProblemLog + expected15ProblemLog, + expected17ProblemLog ); } public void test0051() { @@ -2309,7 +2338,7 @@ public void test0051() { "1. ERROR in X.java (at line 2)\n" + " void foo(java.util.List2<String>... args) {}\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 2)\n" + " void foo(java.util.List2<String>... args) {}\n" + @@ -2319,7 +2348,7 @@ public void test0051() { "3. ERROR in X.java (at line 2)\n" + " void foo(java.util.List2<String>... args) {}\n" + " ^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"; String expected14ProblemLog = expected13ProblemLog; @@ -2431,4 +2460,158 @@ public void test0053() { expected15ProblemLog ); } +public void test0054() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try (int i = 0) {};\n" + + " }\n" + + "}\n" + }; + + String expected13ProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (int i = 0) {};\n" + + " ^^^^^^^^^\n" + + "Resource specification not allowed here for source level below 1.7\n" + + "----------\n"; + String expected14ProblemLog = + expected13ProblemLog; + + String expected15ProblemLog = + expected14ProblemLog; + + String expected17ProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (int i = 0) {};\n" + + " ^^^\n" + + "The resource type int does not implement java.lang.AutoCloseable\n" + + "----------\n"; + runComplianceParserTest( + testFiles, + expected13ProblemLog, + expected14ProblemLog, + expected15ProblemLog, + expected17ProblemLog + ); +} +// test that use of multi-catch is flagged accordingly +public void test0055() { + if(this.complianceLevel >= ClassFileConstants.JDK1_7) { + return; + } + String[] testFiles = new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println();\n" + + " Reader r = new FileReader(args[0]);\n" + + " r.read();\n" + + " } catch(IOException | RuntimeException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n" + }; + + String expected13ProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " } catch(IOException | RuntimeException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Multi-catch parameters are not allowed for source level below 1.7\n" + + "----------\n"; + String expected14ProblemLog = + expected13ProblemLog; + + String expected15ProblemLog = + expected14ProblemLog; + + runComplianceParserTest( + testFiles, + expected13ProblemLog, + expected14ProblemLog, + expected15ProblemLog + ); +} +// rethrow should not be precisely computed in 1.6- +public void test0056() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new DaughterOfFoo();\n"+ + " } catch(Foo e) {\n" + + " try {\n" + + " throw e;\n" + + " } catch (SonOfFoo e1) {\n" + + " e1.printStackTrace();\n" + + " } catch (Foo e1) {}\n" + + " }\n" + + " }\n" + + "}\n"+ + "class Foo extends Exception {}\n"+ + "class SonOfFoo extends Foo {}\n"+ + "class DaughterOfFoo extends Foo {}\n" + }; + + String expected13ProblemLog = + "----------\n" + + "1. WARNING in X.java (at line 14)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 16)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"; + String expected14ProblemLog = + expected13ProblemLog; + + String expected15ProblemLog = + expected14ProblemLog; + + String expected17ProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " } catch (SonOfFoo e1) {\n" + + " ^^^^^^^^\n" + + "Unreachable catch block for SonOfFoo. This exception is never thrown from the try statement body\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 16)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"; + runComplianceParserTest( + testFiles, + expected13ProblemLog, + expected14ProblemLog, + expected15ProblemLog, + expected17ProblemLog + ); +} } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java index c377c8ecfd..c9e6ee2542 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java @@ -4,7 +4,7 @@ * 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 *******************************************************************************/ @@ -33,7 +33,7 @@ public class DietRecoveryTest extends AbstractCompilerTest { public static boolean optimizeStringLiterals = false; public static long sourceLevel = ClassFileConstants.JDK1_3; //$NON-NLS-1$ static { -// TESTS_NUMBERS = new int[] { 113 }; +// TESTS_NUMBERS = new int[] { 75 }; } public static Test suite() { return buildAllCompliancesTestSuite(DietRecoveryTest.class); @@ -6610,10 +6610,11 @@ public void test110() { " super();\n" + " }\n" + " void foo() {\n" + - " try \n" + + " try\n" + " {\n" + " }\n" + - " catch (Exception e) {\n" + + " catch (Exception e)\n" + + " {\n" + " }\n" + " }\n" + " }\n" + @@ -6724,10 +6725,11 @@ public void test112() { " super();\n" + " }\n" + " public void foo() {\n" + - " try \n" + + " try\n" + " {\n" + " }\n" + - " catch (Exception e) {\n" + + " catch (Exception e)\n" + + " {\n" + " bar(\"blabla\");\n" + " throw new Exception(prefix);\n" + " }\n" + @@ -7329,11 +7331,12 @@ public void test120() { " super();\n" + " }\n" + " void foo() {\n" + - " try \n" + + " try\n" + " {\n" + " System.out.println();\n" + " }\n" + - " catch (Exception e) {\n" + + " catch (Exception e)\n" + + " {\n" + " }\n" + " class Z {\n" + " Z() {\n" + @@ -7394,11 +7397,12 @@ public void test121() { " super();\n" + " }\n" + " void foo() {\n" + - " try \n" + + " try\n" + " {\n" + " System.out.println();\n" + " }\n" + - " catch (Exception e) {\n" + + " catch (Exception e)\n" + + " {\n" + " class Z {\n" + " Z() {\n" + " super();\n" + @@ -7466,10 +7470,11 @@ public void test122() { " super();\n" + " }\n" + " public void func1() {\n" + - " try \n" + + " try\n" + " {\n" + " }\n" + - " catch (Exception exception) {\n" + + " catch (Exception exception)\n" + + " {\n" + " exception.printStackTrace();\n" + " }\n" + " class Clazz {\n" + @@ -7533,12 +7538,13 @@ public void test123() { " }\n" + " void aMethod() {\n" + " int i = 0;\n" + - " try \n" + + " try\n" + " {\n" + " switch (i) {\n" + " }\n" + " }\n" + - " catch (Exception ex) {\n" + + " catch (Exception ex)\n" + + " {\n" + " }\n" + " class Nested {\n" + " Nested() {\n" + diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/GenericsCompletionParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/GenericsCompletionParserTest.java index d1de10a1d9..b40d74f039 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/GenericsCompletionParserTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/GenericsCompletionParserTest.java @@ -4,7 +4,7 @@ * 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 *******************************************************************************/ @@ -1918,10 +1918,11 @@ public void test0044_Method(){ int cursorLocation = str.indexOf("Y<Z>.") + completeBehind.length() - 1; String expectedCompletionNodeToString = "<CompleteOnException:Y<Z>.>"; String expectedParentNodeToString = - "try \n" + + "try\n" + " {\n" + " }\n" + - "catch (<CompleteOnException:Y<Z>.> ) {\n" + + "catch (<CompleteOnException:Y<Z>.> )\n" + + " {\n" + " }"; String completionIdentifier = ""; String expectedReplacedSource = "Y<Z>."; @@ -1930,10 +1931,11 @@ public void test0044_Method(){ " public X() {\n" + " }\n" + " void foo() {\n" + - " try \n" + + " try\n" + " {\n" + " }\n" + - " catch (<CompleteOnException:Y<Z>.> ) {\n" + + " catch (<CompleteOnException:Y<Z>.> )\n" + + " {\n" + " }\n" + " }\n" + "}\n"; @@ -1996,10 +1998,11 @@ public void test0045_Method(){ int cursorLocation = str.indexOf("Y<Z>.") + completeBehind.length() - 1; String expectedCompletionNodeToString = "<CompleteOnException:Y<Z>.>"; String expectedParentNodeToString = - "try \n" + + "try\n" + " {\n" + " }\n" + - "catch (<CompleteOnException:Y<Z>.> ) {\n" + + "catch (<CompleteOnException:Y<Z>.> )\n" + + " {\n" + " }"; String completionIdentifier = ""; String expectedReplacedSource = "Y<Z>."; @@ -2008,10 +2011,11 @@ public void test0045_Method(){ " public X() {\n" + " }\n" + " void foo() {\n" + - " try \n" + + " try\n" + " {\n" + " }\n" + - " catch (<CompleteOnException:Y<Z>.> ) {\n" + + " catch (<CompleteOnException:Y<Z>.> )\n" + + " {\n" + " }\n" + " }\n" + "}\n"; @@ -6342,7 +6346,7 @@ public void test0131_Method(){ " public X() {\n" + " }\n" + " void foo() {\n" + - " Object[] o = Y<<CompleteOnType:Z>>;\n" + + " Object[] o = new Y<<CompleteOnType:Z>>();\n" + " }\n" + "}\n"; @@ -6409,7 +6413,7 @@ public void test0132_Method(){ " public X() {\n" + " }\n" + " void foo() {\n" + - " Object[] o = Y<<CompleteOnType:Z>>;\n" + + " Object[] o = new Y<<CompleteOnType:Z>>();\n" + " }\n" + "}\n"; @@ -6476,7 +6480,7 @@ public void test0133_Method(){ " public X() {\n" + " }\n" + " void foo() {\n" + - " Object[] o = Y<<CompleteOnType:Z>>;\n" + + " Object[] o = new Y<<CompleteOnType:Z>>();\n" + " }\n" + "}\n"; @@ -6543,7 +6547,7 @@ public void test0134_Method(){ " public X() {\n" + " }\n" + " void foo() {\n" + - " Object[] o = Y<<CompleteOnType:Z>>;\n" + + " Object[] o = new Y<<CompleteOnType:Z>>();\n" + " }\n" + "}\n"; @@ -10772,13 +10776,15 @@ public void test0213_Method() { int cursorLocation = str.lastIndexOf("IZZ") + completeBehind.length() - 1; String expectedCompletionNodeToString = "<CompleteOnException:Top<Object>.IZZ>"; String expectedParentNodeToString = - "try \n" + + "try\n" + " {\n" + " throwing();\n" + " }\n" + - "catch (IllegalAccessException e) {\n" + + "catch (IllegalAccessException e)\n" + + " {\n" + " }\n" + - "catch (<CompleteOnException:Top<Object>.IZZ> ) {\n" + + "catch (<CompleteOnException:Top<Object>.IZZ> )\n" + + " {\n" + " }"; String completionIdentifier = "IZZ"; String expectedReplacedSource = "Top<Object>.IZZ"; @@ -10787,13 +10793,15 @@ public void test0213_Method() { " public X() {\n" + " }\n" + " public boolean foo() {\n" + - " try \n" + + " try\n" + " {\n" + " throwing();\n" + " }\n" + - " catch (IllegalAccessException e) {\n" + + " catch (IllegalAccessException e)\n" + + " {\n" + " }\n" + - " catch (<CompleteOnException:Top<Object>.IZZ> ) {\n" + + " catch (<CompleteOnException:Top<Object>.IZZ> )\n" + + " {\n" + " }\n" + " }\n" + "}\n"; @@ -11133,4 +11141,111 @@ public void test0220_Diet() { expectedReplacedSource, "diet ast"); } +public void testBug351426(){ + String str = + "public class X<T> {\n" + + " void foo() {\n" + + " X<String> x = new X<>();\n" + + " }\n" + + "}"; + + + String completeBehind = "new X<"; + int cursorLocation = str.indexOf("new X<") + completeBehind.length() - 1; + String expectedCompletionNodeToString = "<CompleteOnType:>"; + String expectedParentNodeToString = "X<<CompleteOnType:>>"; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X<T> {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " X<String> x = new X<<CompleteOnType:>>();\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void testBug351426b(){ + String str = + "public class X<T> {\n" + + " static class X1<E>{}\n" + + " void foo() {\n" + + " X1<String> x = new X.X1<>();\n" + + " }\n" + + "}"; + + + String completeBehind = "new X.X1<"; + int cursorLocation = str.indexOf("new X.X1<") + completeBehind.length() - 1; + String expectedCompletionNodeToString = "<CompleteOnType:>"; + String expectedParentNodeToString = "X.X1<<CompleteOnType:>>"; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X<T> {\n" + + " static class X1<E> {\n" + + " X1() {\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " X1<String> x = new X.X1<<CompleteOnType:>>();\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void testBug351426c(){ + String str = + "public class X<T> {\n" + + " public X<String> foo() {\n" + + " return new X<>();\n" + + " }\n" + + "}"; + + + String completeBehind = "new X<"; + int cursorLocation = str.indexOf("new X<") + completeBehind.length() - 1; + String expectedCompletionNodeToString = "<CompleteOnType:>"; + String expectedParentNodeToString = "X<<CompleteOnType:>>"; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X<T> {\n" + + " public X() {\n" + + " }\n" + + " public X<String> foo() {\n" + + " return new X<<CompleteOnType:>>();\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ParserTest1_7.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ParserTest1_7.java new file mode 100644 index 0000000000..03177dcd39 --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ParserTest1_7.java @@ -0,0 +1,1255 @@ +/******************************************************************************* + * Copyright (c) 2011 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 + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import java.util.Locale; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.parser.Parser; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; + +public class ParserTest1_7 extends AbstractCompilerTest { + public static final boolean ONLY_DIET_PLUS_BODY_WITH_STATEMENT_RECOVERY = false; + +static { +// TESTS_NAMES = new String[] { "test0037"}; +// TESTS_RANGE = new int[] {10, 20}; +// TESTS_NUMBERS = new int[] { 10 }; +} +public static Class testClass() { + return ParserTest1_7.class; +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_7); +} +public ParserTest1_7(String testName){ + super(testName); +} +public void checkParse( + char[] source, + String expectedDietUnitToString, + String expectedDietWithStatementRecoveryUnitToString, + String expectedDietPlusBodyUnitToString, + String expectedDietPlusBodyWithStatementRecoveryUnitToString, + String expectedFullUnitToString, + String expectedFullWithStatementRecoveryUnitToString, + String testName) { + + /* using regular parser in DIET mode */ + if(!ONLY_DIET_PLUS_BODY_WITH_STATEMENT_RECOVERY){ + Parser parser = + new Parser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(getCompilerOptions()), + new DefaultProblemFactory(Locale.getDefault())), + true); + parser.setStatementsRecovery(false); + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult); + String computedUnitToString = computedUnit.toString(); + if (!expectedDietUnitToString.equals(computedUnitToString)){ + System.out.println(Util.displayString(computedUnitToString)); + } + assertEquals( + "Invalid unit diet structure" + testName, + expectedDietUnitToString, + computedUnitToString); + } + /* using regular parser in DIET mode and statementRecoveryEnabled */ + if(!ONLY_DIET_PLUS_BODY_WITH_STATEMENT_RECOVERY){ + Parser parser = + new Parser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(getCompilerOptions()), + new DefaultProblemFactory(Locale.getDefault())), + true); + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult); + String computedUnitToString = computedUnit.toString(); + if (!expectedDietWithStatementRecoveryUnitToString.equals(computedUnitToString)){ + System.out.println(Util.displayString(computedUnitToString)); + } + assertEquals( + "Invalid unit diet structure with statement recovery enabled" + testName, + expectedDietWithStatementRecoveryUnitToString, + computedUnitToString); + } + /* using regular parser in DIET mode + getMethodBodies */ + if(!ONLY_DIET_PLUS_BODY_WITH_STATEMENT_RECOVERY){ + Parser parser = + new Parser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(getCompilerOptions()), + new DefaultProblemFactory(Locale.getDefault())), + true); + parser.setStatementsRecovery(false); + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult); + String computedUnitToString = computedUnit.toString(); + if (!expectedDietUnitToString.equals(computedUnitToString)){ + System.out.println(Util.displayString(computedUnitToString)); + } + assertEquals( + "Invalid unit diet structure" + testName, + expectedDietUnitToString, + computedUnitToString); + if (computedUnit.types != null) { + for (int i = 0, length = computedUnit.types.length; i < length; i++){ + computedUnit.types[i].parseMethods(parser, computedUnit); + } + } + computedUnitToString = computedUnit.toString(); + if (!expectedDietPlusBodyUnitToString.equals(computedUnitToString)){ + System.out.println(Util.displayString(computedUnitToString)); + } + + assertEquals( + "Invalid unit diet+body structure" + testName, + expectedDietPlusBodyUnitToString, + computedUnitToString); + } + /* using regular parser in DIET mode + getMethodBodies and statementRecoveryEnabled */ + { + Parser parser = + new Parser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(getCompilerOptions()), + new DefaultProblemFactory(Locale.getDefault())), + true); + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult); + String computedUnitToString = computedUnit.toString(); + if (!expectedDietWithStatementRecoveryUnitToString.equals(computedUnitToString)){ + System.out.println(Util.displayString(computedUnitToString)); + } + assertEquals( + "Invalid unit diet structure" + testName, + expectedDietWithStatementRecoveryUnitToString, + computedUnitToString); + if (computedUnit.types != null) { + for (int i = 0, length = computedUnit.types.length; i < length; i++){ + computedUnit.types[i].parseMethods(parser, computedUnit); + } + } + computedUnitToString = computedUnit.toString(); + if (!expectedDietPlusBodyWithStatementRecoveryUnitToString.equals(computedUnitToString)){ + System.out.println(Util.displayString(computedUnitToString)); + } + + assertEquals( + "Invalid unit diet+body structure with statement recovery enabled" + testName, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + computedUnitToString); + } + { + /* using regular parser in FULL mode */ + if(!ONLY_DIET_PLUS_BODY_WITH_STATEMENT_RECOVERY){ + Parser parser = + new Parser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(getCompilerOptions()), + new DefaultProblemFactory(Locale.getDefault())), + true); + parser.setStatementsRecovery(false); + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration computedUnit = parser.parse(sourceUnit, compilationResult); + String computedUnitToString = computedUnit.toString(); + if (!expectedFullUnitToString.equals(computedUnitToString)){ + System.out.println(Util.displayString(computedUnitToString)); + } + assertEquals( + "Invalid unit full structure" + testName, + expectedFullUnitToString, + computedUnitToString); + + } + } + /* using regular parser in FULL mode and statementRecoveryEnabled */ + if(!ONLY_DIET_PLUS_BODY_WITH_STATEMENT_RECOVERY){ + Parser parser = + new Parser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(getCompilerOptions()), + new DefaultProblemFactory(Locale.getDefault())), + true); + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration computedUnit = parser.parse(sourceUnit, compilationResult); + String computedUnitToString = computedUnit.toString(); + if (!expectedFullWithStatementRecoveryUnitToString.equals(computedUnitToString)){ + System.out.println(Util.displayString(computedUnitToString)); + } + assertEquals( + "Invalid unit full structure with statement recovery enabled" + testName, + expectedFullWithStatementRecoveryUnitToString, + computedUnitToString); + + } +} + +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_7); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7); + return options; +} +public void test0001() { + + String s = + "public class A {\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\")) {\n" + + " System.out.println(reader.read());\n" + + " } catch(FileNotFoundException | IOException | Exception e) {\n" + + " e.printStackTrace();\n" + + " } finally {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}"; + + String expectedDietUnitToString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException | IOException | Exception e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException | IOException | Exception e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException | IOException | Exception e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "<test>"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0002() { + + String s = + "public class A {\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\")) {\n" + + " System.out.println(reader.read());\n" + + " } catch(FileNotFoundException e) {\n" + + " e.printStackTrace();\n" + + " } finally {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}"; + + String expectedDietUnitToString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "<test>"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0003() { + + String s = + "public class A {\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\")) {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " }\n" + + "}"; + + String expectedDietUnitToString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "<test>"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0004() { + + String s = + "public class A {\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\")) {\n" + + " System.out.println(reader.read());\n" + + " } finally {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}"; + + String expectedDietUnitToString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "<test>"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0005() { + + String s = + "public class A {\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\")) {\n" + + " System.out.println(reader.read());\n" + + " } catch(FileNotFoundException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}"; + + String expectedDietUnitToString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "<test>"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0006() { + + String s = + "public class A {\n" + + " public void foo(String fileName) {\n" + + " try {\n" + + " System.out.println(reader.read());\n" + + " } catch(FileNotFoundException | IOException | Exception e) {\n" + + " e.printStackTrace();\n" + + " } finally {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}"; + + String expectedDietUnitToString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException | IOException | Exception e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException | IOException | Exception e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException | IOException | Exception e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.out.println(\"Finishing try-with-resources\");\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "<test>"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0007() { + + String s = + "public class A {\n" + + " public void foo(String fileName) {\n" + + " List<String> l = new ArrayList<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}"; + + String expectedDietUnitToString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " List<String> l = new ArrayList<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " List<String> l = new ArrayList<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " List<String> l = new ArrayList<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "<test>"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0008() { + + String s = + "public class A {\n" + + " public void foo(String fileName) {\n" + + " List<> l = new ArrayList<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}"; + + String expectedDietUnitToString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " List<> l = new ArrayList<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " List<> l = new ArrayList<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " List<> l = new ArrayList<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "<test>"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0009() { + + String s = + "public class A {\n" + + " public void foo(String fileName) {\n" + + " List<String> l = new java.util.ArrayList<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}"; + + String expectedDietUnitToString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " List<String> l = new java.util.ArrayList<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " List<String> l = new java.util.ArrayList<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " List<String> l = new java.util.ArrayList<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "<test>"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0010() { + + String s = + "public class A {\n" + + " public void foo(String fileName) {\n" + + " B<String>.C<Integer> o = new B<>.C<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}"; + + String expectedDietUnitToString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " B<String>.C<Integer> o = new B<>.C<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " B<String>.C<Integer> o = new B<>.C<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " B<String>.C<Integer> o = new B<>.C<>();\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "<test>"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0011() { + + String s = + "public class A {\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\");) {\n" + + " System.out.println(reader.read());\n" + + " } catch(FileNotFoundException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}"; + + String expectedDietUnitToString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "<test>"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0012() { + + String s = + "public class A {\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\");\n" + + " Reader reader2 = new FileReader(\"fileName\");) {\n" + + " System.out.println(reader.read());\n" + + " } catch(FileNotFoundException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}"; + + String expectedDietUnitToString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\");\n" + + " Reader reader2 = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\");\n" + + " Reader reader2 = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo(String fileName) {\n" + + " try (Reader reader = new FileReader(\"fileName\");\n" + + " Reader reader2 = new FileReader(\"fileName\"))\n" + + " {\n" + + " System.out.println(reader.read());\n" + + " }\n" + + " catch (FileNotFoundException e)\n" + + " {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "<test>"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +} diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ReferenceTypeCompletionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ReferenceTypeCompletionTest.java index 5fb1b38873..a970296579 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ReferenceTypeCompletionTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ReferenceTypeCompletionTest.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 *******************************************************************************/ @@ -152,11 +152,12 @@ public void testCatchClause1() { " Bar() {\n" + " }\n" + " void foo() {\n" + - " try \n" + + " try\n" + " {\n" + " fred();\n" + " }\n" + - " catch (<CompleteOnException:X> ) {\n" + + " catch (<CompleteOnException:X> )\n" + + " {\n" + " }\n" + " }\n" + "}\n", @@ -191,11 +192,12 @@ public void testCatchClause2() { " Bar() {\n" + " }\n" + " void foo() {\n" + - " try \n" + + " try\n" + " {\n" + " fred();\n" + " }\n" + - " catch (<CompleteOnException:X> ) {\n" + + " catch (<CompleteOnException:X> )\n" + + " {\n" + " }\n" + " }\n" + "}\n", @@ -230,11 +232,12 @@ public void testCatchClause3() { " Bar() {\n" + " }\n" + " void foo() {\n" + - " try \n" + + " try\n" + " {\n" + " fred();\n" + " }\n" + - " catch (<CompleteOnException:x.y.X> ) {\n" + + " catch (<CompleteOnException:x.y.X> )\n" + + " {\n" + " }\n" + " }\n" + "}\n", diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java index 4d5e4b336b..01a357dd18 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -3619,15 +3619,18 @@ public void test0044() { " public void doSomething() throws FileNotFoundException, EOFException, SAXException {\n" + " }\n" + " public void doSomethingElse() {\n" + - " try \n" + + " try\n" + " {\n" + " doSomething();\n" + " }\n" + - " catch (SAXException exception) {\n" + + " catch (SAXException exception)\n" + + " {\n" + " }\n" + - " catch (FileNotFoundException exception) {\n" + + " catch (FileNotFoundException exception)\n" + + " {\n" + " }\n" + - " catch ($missing$ $missing$) {\n" + + " catch ($missing$ $missing$)\n" + + " {\n" + " }\n" + " }\n" + "}\n"; diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest_1_5.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest_1_5.java index f27409b091..a6b8192712 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest_1_5.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest_1_5.java @@ -4,7 +4,7 @@ * 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 *******************************************************************************/ @@ -281,7 +281,7 @@ public void test0001() { " void foo(Collection c) {\n" + " for (String s : c) \n" + " {\n" + - " try \n" + + " try\n" + " {\n" + " foo();\n" + " }\n" + diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java index 728a9f3f07..44d8b3c191 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 *******************************************************************************/ @@ -119,6 +119,7 @@ public static Test suite() { if ((possibleComplianceLevels & AbstractCompilerTest.F_1_7) != 0) { ArrayList tests_1_7 = (ArrayList)testClasses.clone(); tests_1_7.addAll(TEST_CLASSES_1_5); + tests_1_7.add(ParserTest1_7.class); // Reset forgotten subsets tests TestCase.TESTS_PREFIX = null; TestCase.TESTS_NAMES = null; 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 1599e90240..62da41cd70 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 335093 - [compiler][null] minimal hook for future null annotation support *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java index 9fc65eaebd..cd1e4ac214 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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,9 @@ import junit.framework.*; public class AmbiguousMethodTest extends AbstractComparableTest { + static { +// TESTS_NAMES = new String [] { "test087" }; + } public AmbiguousMethodTest(String name) { super(name); } @@ -3269,6 +3272,7 @@ public void test075() { } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=268837 +// See that this test case exhibits the bug 345947 public void test076() { this.runNegativeTest( new String[] { @@ -3320,97 +3324,102 @@ public void test076() { "}" }, "----------\n" + - "1. ERROR in X.java (at line 15)\n" + + "1. ERROR in X.java (at line 8)\n" + + " <U> J<String> b();\n" + + " ^^^\n" + + "Name clash: The method b() of type J<E> has the same erasure as b() of type I<E> but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + " J<Integer> b = ints.a();\n" + " ^^^^^^^^\n" + "Type mismatch: cannot convert from J<String> to J<Integer>\n" + "----------\n" + - "2. ERROR in X.java (at line 16)\n" + + "3. ERROR in X.java (at line 16)\n" + " J<Object> c = ints.a();\n" + " ^^^^^^^^\n" + "Type mismatch: cannot convert from J<String> to J<Object>\n" + "----------\n" + - "3. WARNING in X.java (at line 17)\n" + + "4. WARNING in X.java (at line 17)\n" + " J d = ints.a();\n" + " ^\n" + "J is a raw type. References to generic type J<E> should be parameterized\n" + "----------\n" + - "4. ERROR in X.java (at line 19)\n" + + "5. ERROR in X.java (at line 19)\n" + " I<Integer> f = ints.a();\n" + " ^^^^^^^^\n" + "Type mismatch: cannot convert from J<String> to I<Integer>\n" + "----------\n" + - "5. ERROR in X.java (at line 20)\n" + + "6. ERROR in X.java (at line 20)\n" + " I<Object> g = ints.a();\n" + " ^^^^^^^^\n" + "Type mismatch: cannot convert from J<String> to I<Object>\n" + "----------\n" + - "6. WARNING in X.java (at line 21)\n" + + "7. WARNING in X.java (at line 21)\n" + " I h = ints.a();\n" + " ^\n" + "I is a raw type. References to generic type I<E> should be parameterized\n" + "----------\n" + - "7. ERROR in X.java (at line 24)\n" + + "8. ERROR in X.java (at line 24)\n" + " ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J<Integer>\n" + "----------\n" + - "8. ERROR in X.java (at line 25)\n" + + "9. ERROR in X.java (at line 25)\n" + " J<String> a = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J<Integer>\n" + "----------\n" + - "9. ERROR in X.java (at line 26)\n" + + "10. ERROR in X.java (at line 26)\n" + " J<Integer> b = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J<Integer>\n" + "----------\n" + - "10. ERROR in X.java (at line 27)\n" + + "11. ERROR in X.java (at line 27)\n" + " J<Object> c = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J<Integer>\n" + "----------\n" + - "11. WARNING in X.java (at line 28)\n" + + "12. WARNING in X.java (at line 28)\n" + " J d = ints.b();\n" + " ^\n" + "J is a raw type. References to generic type J<E> should be parameterized\n" + "----------\n" + - "12. ERROR in X.java (at line 28)\n" + + "13. ERROR in X.java (at line 28)\n" + " J d = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J<Integer>\n" + "----------\n" + - "13. ERROR in X.java (at line 29)\n" + + "14. ERROR in X.java (at line 29)\n" + " I<String> e = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J<Integer>\n" + "----------\n" + - "14. ERROR in X.java (at line 30)\n" + + "15. ERROR in X.java (at line 30)\n" + " I<Integer> f = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J<Integer>\n" + "----------\n" + - "15. ERROR in X.java (at line 31)\n" + + "16. ERROR in X.java (at line 31)\n" + " I<Object> g = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J<Integer>\n" + "----------\n" + - "16. WARNING in X.java (at line 32)\n" + + "17. WARNING in X.java (at line 32)\n" + " I h = ints.b();\n" + " ^\n" + "I is a raw type. References to generic type I<E> should be parameterized\n" + "----------\n" + - "17. ERROR in X.java (at line 32)\n" + + "18. ERROR in X.java (at line 32)\n" + " I h = ints.b();\n" + " ^\n" + "The method b() is ambiguous for the type J<Integer>\n" + "----------\n" + - "18. WARNING in X.java (at line 39)\n" + + "19. WARNING in X.java (at line 39)\n" + " J d = ints.c();\n" + " ^\n" + "J is a raw type. References to generic type J<E> should be parameterized\n" + "----------\n" + - "19. WARNING in X.java (at line 43)\n" + + "20. WARNING in X.java (at line 43)\n" + " I h = ints.c();\n" + " ^\n" + "I is a raw type. References to generic type I<E> should be parameterized\n" + @@ -3479,8 +3488,9 @@ public void test078() { } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=292350 +// See that this test case exhibits the bug 345947 public void test079() { - this.runConformTest( + this.runNegativeTest( new String[] { "X.java", "interface I<T> {}\n" + @@ -3499,7 +3509,17 @@ public void test079() { " void y(Two t) { t.y(); }\n" + "}" }, - "" + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " <T extends A> I<T> x() throws IllegalAccessError;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method x() of type Two has the same erasure as x() of type One but does not override it\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " I<B> y() throws IllegalAccessError;\n" + + " ^\n" + + "Type safety: The return type I<B> for y() from the type Two needs unchecked conversion to conform to I<A> from the type One\n" + + "----------\n" ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=293384 @@ -3846,4 +3866,25 @@ public void test086() { }, "In A.set(Object)"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=321485 +public void test087() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static <T> List<T> with(List<? extends T> p) { return null; } \n" + + " public static <T> Collection<T> with(Collection<T> p) { return null; }\n" + + " static { with(null); }\n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " static { with(null); }\n" + + " ^^^^\n" + + "The method with(List<? extends Object>) is ambiguous for the type X\n" + + "----------\n" + ); +} } 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 5e777f0df0..36aaf2e158 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 @@ -9798,6 +9798,29 @@ public void test297() { customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); customOptions.put(CompilerOptions.OPTION_ReportComparingIdentical, CompilerOptions.ERROR); customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + + String expectedErrors = + "----------\n" + + "1. ERROR in A.java (at line 15)\n" + + " return i == i;\n" + + " ^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n"; + + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + expectedErrors = + "----------\n" + + "1. ERROR in A.java (at line 10)\n" + + " public final Object build(Class<? super Object>... objects) {\n" + + " ^^^^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter objects\n" + + "----------\n" + + "2. ERROR in A.java (at line 15)\n" + + " return i == i;\n" + + " ^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n"; + } String testFiles [] = new String[] { "A.java", "public class A {\n" + @@ -9820,12 +9843,7 @@ public void test297() { }; runNegativeTest( testFiles, - "----------\n" + - "1. ERROR in A.java (at line 15)\n" + - " return i == i;\n" + - " ^^^^^^\n" + - "Comparing identical expressions\n" + - "----------\n", + expectedErrors, null, true, customOptions); 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 0a23f5005e..2b6fb54846 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 @@ -1857,8 +1857,9 @@ public void test012b(){ " <option key=\"org.eclipse.jdt.core.compiler.problem.parameterAssignment\" value=\"ignore\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment\" value=\"ignore\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.potentialNullReference\" value=\"ignore\"/>\n" + - " <option key=\"org.eclipse.jdt.core.compiler.problem.rawTypeReference\" value=\"warning\"/>\n" + + " <option key=\"org.eclipse.jdt.core.compiler.problem.rawTypeReference\" value=\"warning\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.redundantNullCheck\" value=\"ignore\"/>\n" + + " <option key=\"org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments\" value=\"ignore\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.redundantSuperinterface\" value=\"ignore\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic\" value=\"ignore\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic\" value=\"ignore\"/>\n" + @@ -10991,7 +10992,7 @@ public void test286_option_files() { "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 1)\n" + " public @interface X {\n" + " ^\n" + - "Syntax error, annotation declarations are only available if source level is 1.5\n" + + "Syntax error, annotation declarations are only available if source level is 1.5 or greater\n" + "----------\n" + "1 problem (1 error)", true /*shouldFlushOutput*/); diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BinaryLiteralTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BinaryLiteralTest.java new file mode 100644 index 0000000000..c05fc9801c --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BinaryLiteralTest.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2011 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 + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class BinaryLiteralTest extends AbstractRegressionTest { + public BinaryLiteralTest(String name) { + super(name); + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_7); + } + + public static Class testClass() { + return BinaryLiteralTest.class; + } + + public void test001() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0b001);\n" + + " }\n" + + "}" + }, + "1"); + } + public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0b);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0b);\n" + + " ^^\n" + + "Invalid binary literal number (only \'0\' and \'1\' are expected)\n" + + "----------\n"); + } + public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0b2);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0b2);\n" + + " ^^\n" + + "Invalid binary literal number (only \'0\' and \'1\' are expected)\n" + + "----------\n"); + } + public void test004() { + Map customedOptions = getCompilerOptions(); + customedOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); + customedOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); + customedOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " System.out.println(0b1110000);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0b1110000);\n" + + " ^^^^^^^^^\n" + + "Binary literals can only be used with source level 1.7 or greater\n" + + "----------\n", + null, + true, + customedOptions); + } + public void test005() { + Map customedOptions = getCompilerOptions(); + customedOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); + customedOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); + customedOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " System.out.println(-0b1110000);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(-0b1110000);\n" + + " ^^^^^^^^^\n" + + "Binary literals can only be used with source level 1.7 or greater\n" + + "----------\n", + null, + true, + customedOptions); + } + public void test006() { + Map customedOptions = getCompilerOptions(); + customedOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); + customedOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); + customedOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " System.out.println(0b1113000);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0b1113000);\n" + + " ^^^^^\n" + + "Binary literals can only be used with source level 1.7 or greater\n" + + "----------\n", + null, + true, + customedOptions); + } +} 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 aa002e8c26..6137984851 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 @@ -13,6 +13,8 @@ package org.eclipse.jdt.core.tests.compiler.regression; import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Comparator; import java.util.HashMap; import java.util.Map; @@ -44,7 +46,7 @@ public CompilerInvocationTests(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[] { "test001" }; +// TESTS_NAMES = new String[] { "test003_task_tags_options" }; // TESTS_NUMBERS = new int[] { 1 }; // TESTS_RANGE = new int[] { 1, -1 }; // TESTS_RANGE = new int[] { 1, 2049 }; @@ -354,6 +356,10 @@ public void test011_problem_categories() { expectedProblemAttributes.put("ArrayConstantsOnlyInArrayInitializers", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("ArrayReferenceRequired", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("AssignmentHasNoEffect", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("AssignmentToMultiCatchParameter", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("AssignmentToResource", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("AutoManagedResourceNotBelow17", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("BinaryLiteralNotBelow17", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("BodyForAbstractMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("BodyForNativeMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("BoundCannotBeArray", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); @@ -373,12 +379,15 @@ public void test011_problem_categories() { expectedProblemAttributes.put("CannotExtendEnum", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("CannotHideAnInstanceMethodWithAStaticMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("CannotImportPackage", new ProblemAttributes(CategorizedProblem.CAT_IMPORT)); + expectedProblemAttributes.put("CannotInferElidedTypes", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("CannotInvokeSuperConstructorInEnum", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("CannotOverrideAStaticMethodWithAnInstanceMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("CannotReadSource", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("CannotReturnInInitializer", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("CannotThrowNull", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("CannotThrowType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("CannotUseDiamondWithAnonymousClasses", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("CannotUseDiamondWithExplicitTypeArguments", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("CannotUseSuperInCodeSnippet", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("ClassExtendFinalClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("CodeCannotBeReached", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); @@ -389,6 +398,7 @@ public void test011_problem_categories() { expectedProblemAttributes.put("ConstructorVarargsArgumentNeedCast", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("CorruptedSignature", new ProblemAttributes(CategorizedProblem.CAT_BUILDPATH)); expectedProblemAttributes.put("DeadCode", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("DiamondNotBelow17", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("DirectInvocationOfAbstractMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("DisallowedTargetForAnnotation", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("DiscouragedReference", new ProblemAttributes(CategorizedProblem.CAT_RESTRICTION)); @@ -401,6 +411,7 @@ public void test011_problem_categories() { expectedProblemAttributes.put("DuplicateField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("DuplicateFinalLocalInitialization", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("DuplicateImport", new ProblemAttributes(CategorizedProblem.CAT_IMPORT)); + expectedProblemAttributes.put("DuplicateInheritedMethods", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("DuplicateLabel", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("DuplicateMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("DuplicateMethodErasure", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); @@ -413,8 +424,8 @@ public void test011_problem_categories() { expectedProblemAttributes.put("DuplicateParameterizedMethods", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("DuplicateSuperInterface", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("DuplicateTargetInTargetAnnotation", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); - expectedProblemAttributes.put("DuplicateTypes", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("DuplicateTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("DuplicateTypes", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("EmptyControlFlowStatement", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("EnclosingInstanceInConstructorCall", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("EndOfSource", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); @@ -443,9 +454,9 @@ public void test011_problem_categories() { expectedProblemAttributes.put("FieldTypeNotVisible", DEPRECATED); expectedProblemAttributes.put("FinalBoundForTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); expectedProblemAttributes.put("FinalFieldAssignment", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); - expectedProblemAttributes.put("FinallyMustCompleteNormally", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("FinalMethodCannotBeOverridden", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("FinalOuterLocalAssignment", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("FinallyMustCompleteNormally", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("ForbiddenReference", new ProblemAttributes(CategorizedProblem.CAT_RESTRICTION)); expectedProblemAttributes.put("GenericConstructorTypeArgumentMismatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("GenericMethodTypeArgumentMismatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); @@ -463,6 +474,7 @@ public void test011_problem_categories() { expectedProblemAttributes.put("IllegalExtendedDimensions", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("IllegalExtendedDimensionsForVarArgs", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("IllegalGenericArray", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalHexaLiteral", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("IllegalInstanceofParameterizedType", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("IllegalInstanceofTypeParameter", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("IllegalModifierCombinationFinalAbstractForClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); @@ -493,6 +505,7 @@ public void test011_problem_categories() { expectedProblemAttributes.put("IllegalQualifiedParameterizedTypeAllocation", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("IllegalStaticModifierForMemberType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("IllegalTypeVariableSuperReference", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("IllegalUnderscorePosition", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("IllegalUsageOfQualifiedTypeReference", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("IllegalVararg", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("IllegalVisibilityModifierCombinationForField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); @@ -517,6 +530,7 @@ public void test011_problem_categories() { expectedProblemAttributes.put("IncorrectArityForParameterizedType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("IncorrectEnclosingInstanceReference", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("IncorrectSwitchType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IncorrectSwitchType17", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("IndirectAccessToStaticField", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); expectedProblemAttributes.put("IndirectAccessToStaticMethod", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); expectedProblemAttributes.put("IndirectAccessToStaticType", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); @@ -537,6 +551,7 @@ public void test011_problem_categories() { expectedProblemAttributes.put("InterfaceNotVisible", DEPRECATED); expectedProblemAttributes.put("InternalTypeNameProvided", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("InvalidAnnotationMemberType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("InvalidBinary", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("InvalidBreak", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("InvalidCatchBlockSequence", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("InvalidCharacterConstant", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); @@ -566,6 +581,7 @@ public void test011_problem_categories() { expectedProblemAttributes.put("InvalidTypeVariableExceptionType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("InvalidUnaryExpression", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("InvalidUnicodeEscape", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidUnionTypeReferenceSequence", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("InvalidUsageOfAnnotationDeclarations", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("InvalidUsageOfAnnotations", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("InvalidUsageOfEnumDeclarations", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); @@ -631,9 +647,9 @@ public void test011_problem_categories() { expectedProblemAttributes.put("JavadocNotVisibleField", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); expectedProblemAttributes.put("JavadocNotVisibleMethod", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); expectedProblemAttributes.put("JavadocNotVisibleType", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocParameterMismatch", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); expectedProblemAttributes.put("JavadocParameterizedConstructorArgumentTypeMismatch", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); expectedProblemAttributes.put("JavadocParameterizedMethodArgumentTypeMismatch", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); - expectedProblemAttributes.put("JavadocParameterMismatch", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); expectedProblemAttributes.put("JavadocTypeArgumentsForRawGenericConstructor", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); expectedProblemAttributes.put("JavadocTypeArgumentsForRawGenericMethod", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); expectedProblemAttributes.put("JavadocUndefinedConstructor", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); @@ -647,16 +663,16 @@ public void test011_problem_categories() { expectedProblemAttributes.put("JavadocUsingDeprecatedField", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); expectedProblemAttributes.put("JavadocUsingDeprecatedMethod", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); expectedProblemAttributes.put("JavadocUsingDeprecatedType", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); - expectedProblemAttributes.put("LocalVariableCannotBeNull", DEPRECATED); expectedProblemAttributes.put("LocalVariableCanOnlyBeNull", DEPRECATED); + expectedProblemAttributes.put("LocalVariableCannotBeNull", DEPRECATED); expectedProblemAttributes.put("LocalVariableHidingField", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); expectedProblemAttributes.put("LocalVariableHidingLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); expectedProblemAttributes.put("LocalVariableIsNeverUsed", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); expectedProblemAttributes.put("LocalVariableMayBeNull", DEPRECATED); expectedProblemAttributes.put("MaskedCatch", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("MethodButWithConstructorName", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); - expectedProblemAttributes.put("MethodCanBeStatic", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); expectedProblemAttributes.put("MethodCanBePotentiallyStatic", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("MethodCanBeStatic", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); expectedProblemAttributes.put("MethodMissingDeprecatedAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); expectedProblemAttributes.put("MethodMustOverride", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("MethodMustOverrideOrImplement", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); @@ -678,6 +694,7 @@ public void test011_problem_categories() { expectedProblemAttributes.put("MissingTypeInConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("MissingTypeInMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("MissingValueForAnnotationMember", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("MultiCatchNotBelow17", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("MustDefineEitherDimensionExpressionsOrInitializer", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("MustSpecifyPackage", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("NativeMethodsCannotBeStrictfp", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); @@ -724,9 +741,9 @@ public void test011_problem_categories() { expectedProblemAttributes.put("PackageCollidesWithType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("PackageIsNotExpectedPackage", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("ParameterAssignment", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("ParameterMismatch", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("ParameterizedConstructorArgumentTypeMismatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("ParameterizedMethodArgumentTypeMismatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); - expectedProblemAttributes.put("ParameterMismatch", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("ParsingError", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("ParsingErrorDeleteToken", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("ParsingErrorDeleteTokens", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); @@ -744,7 +761,9 @@ public void test011_problem_categories() { expectedProblemAttributes.put("ParsingErrorOnKeywordNoSuggestion", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("ParsingErrorReplaceTokens", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("ParsingErrorUnexpectedEOF", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("PolymorphicMethodNotBelow17", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("PossibleAccidentalBooleanAssignment", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("PotentialHeapPollutionFromVararg", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW)); expectedProblemAttributes.put("PotentialNullLocalVariableReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("PublicClassMustMatchFileName", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("RawMemberTypeCannotBeParameterized", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); @@ -752,24 +771,31 @@ public void test011_problem_categories() { expectedProblemAttributes.put("RecursiveConstructorInvocation", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("RedefinedArgument", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("RedefinedLocal", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("RedundantSpecificationOfTypeArguments", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); expectedProblemAttributes.put("RedundantLocalVariableNullAssignment", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("RedundantNullCheckOnNonNullLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("RedundantNullCheckOnNullLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("RedundantSuperinterface", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); expectedProblemAttributes.put("ReferenceToForwardField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("ReferenceToForwardTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("ResourceHasToImplementAutoCloseable", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("ReturnTypeAmbiguous", DEPRECATED); expectedProblemAttributes.put("ReturnTypeCannotBeVoidArray", DEPRECATED); expectedProblemAttributes.put("ReturnTypeInheritedNameHidesEnclosingName", DEPRECATED); expectedProblemAttributes.put("ReturnTypeInternalNameProvided", DEPRECATED); expectedProblemAttributes.put("ReturnTypeNotFound", DEPRECATED); expectedProblemAttributes.put("ReturnTypeNotVisible", DEPRECATED); + expectedProblemAttributes.put("SafeVarargsOnFixedArityMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("SafeVarargsOnNonFinalInstanceMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("ShouldImplementHashcode", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("ShouldReturnValue", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("StaticInheritedMethodConflicts", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("StaticMemberOfParameterizedType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("StaticMethodRequested", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("StringConstantIsExceedingUtf8Limit", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SuperInterfaceMustBeAnInterface", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SuperInterfacesCollide", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SuperTypeUsingWildcard", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("SuperclassAmbiguous", DEPRECATED); expectedProblemAttributes.put("SuperclassInheritedNameHidesEnclosingName", DEPRECATED); expectedProblemAttributes.put("SuperclassInternalNameProvided", DEPRECATED); @@ -777,9 +803,7 @@ public void test011_problem_categories() { expectedProblemAttributes.put("SuperclassNotFound", DEPRECATED); expectedProblemAttributes.put("SuperclassNotVisible", DEPRECATED); expectedProblemAttributes.put("SuperfluousSemicolon", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); - expectedProblemAttributes.put("SuperInterfaceMustBeAnInterface", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); - expectedProblemAttributes.put("SuperInterfacesCollide", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); - expectedProblemAttributes.put("SuperTypeUsingWildcard", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SwitchOnStringsNotBelow17", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("Task", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("ThisInStaticContext", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("ThisSuperDuringConstructorInvocation", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); @@ -813,12 +837,14 @@ public void test011_problem_categories() { expectedProblemAttributes.put("UndefinedName", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("UndefinedType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("UndefinedTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("UnderscoresInLiteralsNotBelow17", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); expectedProblemAttributes.put("UndocumentedEmptyBlock", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); expectedProblemAttributes.put("UnexpectedStaticModifierForField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("UnexpectedStaticModifierForMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("UnhandledException", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("UnhandledExceptionInDefaultConstructor", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("UnhandledExceptionInImplicitConstructorCall", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("UnhandledExceptionOnAutoClose", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("UnhandledWarningToken", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); expectedProblemAttributes.put("UninitializedBlankFinalField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("UninitializedLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); @@ -827,7 +853,6 @@ public void test011_problem_categories() { expectedProblemAttributes.put("UnnecessaryCast", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); expectedProblemAttributes.put("UnnecessaryElse", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); expectedProblemAttributes.put("UnnecessaryInstanceof", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); - expectedProblemAttributes.put("UnnecessaryOperator", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); expectedProblemAttributes.put("UnnecessaryNLSTag", new ProblemAttributes(CategorizedProblem.CAT_NLS)); expectedProblemAttributes.put("UnqualifiedFieldAccess", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); expectedProblemAttributes.put("UnreachableCatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); @@ -871,6 +896,13 @@ public void test011_problem_categories() { StringBuffer failures = new StringBuffer(); StringBuffer correctResult = new StringBuffer(70000); Field[] fields = (iProblemClass = IProblem.class).getFields(); + Arrays.sort(fields, new Comparator() { + public int compare(Object o1, Object o2) { + Field field1 = (Field) o1; + Field field2 = (Field) o2; + return field1.getName().compareTo(field2.getName()); + } + }); boolean watchInternalCategory = false, printHeader = true; for (int i = 0, length = fields.length; i < length; i++) { Field field = fields[i]; @@ -991,6 +1023,10 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("ArrayConstantsOnlyInArrayInitializers", SKIP); expectedProblemAttributes.put("ArrayReferenceRequired", SKIP); expectedProblemAttributes.put("AssignmentHasNoEffect", new ProblemAttributes(JavaCore.COMPILER_PB_NO_EFFECT_ASSIGNMENT)); + expectedProblemAttributes.put("AssignmentToMultiCatchParameter", SKIP); + expectedProblemAttributes.put("AssignmentToResource", SKIP); + expectedProblemAttributes.put("AutoManagedResourceNotBelow17", SKIP); + expectedProblemAttributes.put("BinaryLiteralNotBelow17", SKIP); expectedProblemAttributes.put("BodyForAbstractMethod", SKIP); expectedProblemAttributes.put("BodyForNativeMethod", SKIP); expectedProblemAttributes.put("BoundCannotBeArray", SKIP); @@ -1010,12 +1046,15 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("CannotExtendEnum", SKIP); expectedProblemAttributes.put("CannotHideAnInstanceMethodWithAStaticMethod", SKIP); expectedProblemAttributes.put("CannotImportPackage", SKIP); + expectedProblemAttributes.put("CannotInferElidedTypes", SKIP); expectedProblemAttributes.put("CannotInvokeSuperConstructorInEnum", SKIP); expectedProblemAttributes.put("CannotOverrideAStaticMethodWithAnInstanceMethod", SKIP); expectedProblemAttributes.put("CannotReadSource", SKIP); expectedProblemAttributes.put("CannotReturnInInitializer", SKIP); expectedProblemAttributes.put("CannotThrowNull", SKIP); expectedProblemAttributes.put("CannotThrowType", SKIP); + expectedProblemAttributes.put("CannotUseDiamondWithAnonymousClasses", SKIP); + expectedProblemAttributes.put("CannotUseDiamondWithExplicitTypeArguments", SKIP); expectedProblemAttributes.put("CannotUseSuperInCodeSnippet", SKIP); expectedProblemAttributes.put("ClassExtendFinalClass", SKIP); expectedProblemAttributes.put("CodeCannotBeReached", SKIP); @@ -1026,6 +1065,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("ConstructorVarargsArgumentNeedCast", new ProblemAttributes(JavaCore.COMPILER_PB_VARARGS_ARGUMENT_NEED_CAST)); expectedProblemAttributes.put("CorruptedSignature", SKIP); expectedProblemAttributes.put("DeadCode", new ProblemAttributes(JavaCore.COMPILER_PB_DEAD_CODE)); + expectedProblemAttributes.put("DiamondNotBelow17", SKIP); expectedProblemAttributes.put("DirectInvocationOfAbstractMethod", SKIP); expectedProblemAttributes.put("DisallowedTargetForAnnotation", SKIP); expectedProblemAttributes.put("DiscouragedReference", new ProblemAttributes(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE)); @@ -1038,6 +1078,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("DuplicateField", SKIP); expectedProblemAttributes.put("DuplicateFinalLocalInitialization", SKIP); expectedProblemAttributes.put("DuplicateImport", SKIP); + expectedProblemAttributes.put("DuplicateInheritedMethods", SKIP); expectedProblemAttributes.put("DuplicateLabel", SKIP); expectedProblemAttributes.put("DuplicateMethod", SKIP); expectedProblemAttributes.put("DuplicateMethodErasure", SKIP); @@ -1050,8 +1091,8 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("DuplicateParameterizedMethods", SKIP); expectedProblemAttributes.put("DuplicateSuperInterface", SKIP); expectedProblemAttributes.put("DuplicateTargetInTargetAnnotation", SKIP); - expectedProblemAttributes.put("DuplicateTypes", SKIP); expectedProblemAttributes.put("DuplicateTypeVariable", SKIP); + expectedProblemAttributes.put("DuplicateTypes", SKIP); expectedProblemAttributes.put("EmptyControlFlowStatement", new ProblemAttributes(JavaCore.COMPILER_PB_EMPTY_STATEMENT)); expectedProblemAttributes.put("EnclosingInstanceInConstructorCall", SKIP); expectedProblemAttributes.put("EndOfSource", SKIP); @@ -1080,9 +1121,9 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("FieldTypeNotVisible", SKIP); expectedProblemAttributes.put("FinalBoundForTypeVariable", new ProblemAttributes(JavaCore.COMPILER_PB_FINAL_PARAMETER_BOUND)); expectedProblemAttributes.put("FinalFieldAssignment", SKIP); - expectedProblemAttributes.put("FinallyMustCompleteNormally", new ProblemAttributes(JavaCore.COMPILER_PB_FINALLY_BLOCK_NOT_COMPLETING)); expectedProblemAttributes.put("FinalMethodCannotBeOverridden", SKIP); expectedProblemAttributes.put("FinalOuterLocalAssignment", SKIP); + expectedProblemAttributes.put("FinallyMustCompleteNormally", new ProblemAttributes(JavaCore.COMPILER_PB_FINALLY_BLOCK_NOT_COMPLETING)); expectedProblemAttributes.put("ForbiddenReference", new ProblemAttributes(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE)); expectedProblemAttributes.put("GenericConstructorTypeArgumentMismatch", SKIP); expectedProblemAttributes.put("GenericMethodTypeArgumentMismatch", SKIP); @@ -1100,6 +1141,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("IllegalExtendedDimensions", SKIP); expectedProblemAttributes.put("IllegalExtendedDimensionsForVarArgs", SKIP); expectedProblemAttributes.put("IllegalGenericArray", SKIP); + expectedProblemAttributes.put("IllegalHexaLiteral", SKIP); expectedProblemAttributes.put("IllegalInstanceofParameterizedType", SKIP); expectedProblemAttributes.put("IllegalInstanceofTypeParameter", SKIP); expectedProblemAttributes.put("IllegalModifierCombinationFinalAbstractForClass", SKIP); @@ -1130,6 +1172,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("IllegalQualifiedParameterizedTypeAllocation", SKIP); expectedProblemAttributes.put("IllegalStaticModifierForMemberType", SKIP); expectedProblemAttributes.put("IllegalTypeVariableSuperReference", SKIP); + expectedProblemAttributes.put("IllegalUnderscorePosition", SKIP); expectedProblemAttributes.put("IllegalUsageOfQualifiedTypeReference", SKIP); expectedProblemAttributes.put("IllegalVararg", SKIP); expectedProblemAttributes.put("IllegalVisibilityModifierCombinationForField", SKIP); @@ -1154,6 +1197,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("IncorrectArityForParameterizedType", SKIP); expectedProblemAttributes.put("IncorrectEnclosingInstanceReference", SKIP); expectedProblemAttributes.put("IncorrectSwitchType", SKIP); + expectedProblemAttributes.put("IncorrectSwitchType17", SKIP); expectedProblemAttributes.put("IndirectAccessToStaticField", new ProblemAttributes(JavaCore.COMPILER_PB_INDIRECT_STATIC_ACCESS)); expectedProblemAttributes.put("IndirectAccessToStaticMethod", new ProblemAttributes(JavaCore.COMPILER_PB_INDIRECT_STATIC_ACCESS)); expectedProblemAttributes.put("IndirectAccessToStaticType", new ProblemAttributes(JavaCore.COMPILER_PB_INDIRECT_STATIC_ACCESS)); @@ -1174,6 +1218,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("InterfaceNotVisible", SKIP); expectedProblemAttributes.put("InternalTypeNameProvided", SKIP); expectedProblemAttributes.put("InvalidAnnotationMemberType", SKIP); + expectedProblemAttributes.put("InvalidBinary", SKIP); expectedProblemAttributes.put("InvalidBreak", SKIP); expectedProblemAttributes.put("InvalidCatchBlockSequence", SKIP); expectedProblemAttributes.put("InvalidCharacterConstant", SKIP); @@ -1203,6 +1248,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("InvalidTypeVariableExceptionType", SKIP); expectedProblemAttributes.put("InvalidUnaryExpression", SKIP); expectedProblemAttributes.put("InvalidUnicodeEscape", SKIP); + expectedProblemAttributes.put("InvalidUnionTypeReferenceSequence", SKIP); expectedProblemAttributes.put("InvalidUsageOfAnnotationDeclarations", SKIP); expectedProblemAttributes.put("InvalidUsageOfAnnotations", SKIP); expectedProblemAttributes.put("InvalidUsageOfEnumDeclarations", SKIP); @@ -1268,9 +1314,9 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("JavadocNotVisibleField", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); expectedProblemAttributes.put("JavadocNotVisibleMethod", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); expectedProblemAttributes.put("JavadocNotVisibleType", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocParameterMismatch", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); expectedProblemAttributes.put("JavadocParameterizedConstructorArgumentTypeMismatch", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); expectedProblemAttributes.put("JavadocParameterizedMethodArgumentTypeMismatch", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); - expectedProblemAttributes.put("JavadocParameterMismatch", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); expectedProblemAttributes.put("JavadocTypeArgumentsForRawGenericConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); expectedProblemAttributes.put("JavadocTypeArgumentsForRawGenericMethod", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); expectedProblemAttributes.put("JavadocUndefinedConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); @@ -1284,16 +1330,16 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("JavadocUsingDeprecatedField", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); expectedProblemAttributes.put("JavadocUsingDeprecatedMethod", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); expectedProblemAttributes.put("JavadocUsingDeprecatedType", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); - expectedProblemAttributes.put("LocalVariableCannotBeNull", SKIP); expectedProblemAttributes.put("LocalVariableCanOnlyBeNull", SKIP); + expectedProblemAttributes.put("LocalVariableCannotBeNull", SKIP); expectedProblemAttributes.put("LocalVariableHidingField", new ProblemAttributes(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING)); expectedProblemAttributes.put("LocalVariableHidingLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING)); expectedProblemAttributes.put("LocalVariableIsNeverUsed", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_LOCAL)); expectedProblemAttributes.put("LocalVariableMayBeNull", SKIP); expectedProblemAttributes.put("MaskedCatch", new ProblemAttributes(JavaCore.COMPILER_PB_HIDDEN_CATCH_BLOCK)); expectedProblemAttributes.put("MethodButWithConstructorName", new ProblemAttributes(JavaCore.COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME)); - expectedProblemAttributes.put("MethodCanBeStatic", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_STATIC_ON_METHOD)); expectedProblemAttributes.put("MethodCanBePotentiallyStatic", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIALLY_MISSING_STATIC_ON_METHOD)); + expectedProblemAttributes.put("MethodCanBeStatic", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_STATIC_ON_METHOD)); expectedProblemAttributes.put("MethodMissingDeprecatedAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION)); expectedProblemAttributes.put("MethodMustOverride", SKIP); expectedProblemAttributes.put("MethodMustOverrideOrImplement", SKIP); @@ -1307,7 +1353,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("MissingEnclosingInstanceForConstructorCall", SKIP); expectedProblemAttributes.put("MissingEnumConstantCase", new ProblemAttributes(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH)); expectedProblemAttributes.put("MissingOverrideAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION)); - expectedProblemAttributes.put("MissingOverrideAnnotationForInterfaceMethodImplementation", SKIP); + expectedProblemAttributes.put("MissingOverrideAnnotationForInterfaceMethodImplementation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION)); expectedProblemAttributes.put("MissingReturnType", SKIP); expectedProblemAttributes.put("MissingSemiColon", SKIP); expectedProblemAttributes.put("MissingSerialVersion", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_SERIAL_VERSION)); @@ -1315,6 +1361,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("MissingTypeInConstructor", SKIP); expectedProblemAttributes.put("MissingTypeInMethod", SKIP); expectedProblemAttributes.put("MissingValueForAnnotationMember", SKIP); + expectedProblemAttributes.put("MultiCatchNotBelow17", SKIP); expectedProblemAttributes.put("MustDefineEitherDimensionExpressionsOrInitializer", SKIP); expectedProblemAttributes.put("MustSpecifyPackage", SKIP); expectedProblemAttributes.put("NativeMethodsCannotBeStrictfp", SKIP); @@ -1361,9 +1408,9 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("PackageCollidesWithType", SKIP); expectedProblemAttributes.put("PackageIsNotExpectedPackage", SKIP); expectedProblemAttributes.put("ParameterAssignment", new ProblemAttributes(JavaCore.COMPILER_PB_PARAMETER_ASSIGNMENT)); + expectedProblemAttributes.put("ParameterMismatch", SKIP); expectedProblemAttributes.put("ParameterizedConstructorArgumentTypeMismatch", SKIP); expectedProblemAttributes.put("ParameterizedMethodArgumentTypeMismatch", SKIP); - expectedProblemAttributes.put("ParameterMismatch", SKIP); expectedProblemAttributes.put("ParsingError", SKIP); expectedProblemAttributes.put("ParsingErrorDeleteToken", SKIP); expectedProblemAttributes.put("ParsingErrorDeleteTokens", SKIP); @@ -1381,7 +1428,9 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("ParsingErrorOnKeywordNoSuggestion", SKIP); expectedProblemAttributes.put("ParsingErrorReplaceTokens", SKIP); expectedProblemAttributes.put("ParsingErrorUnexpectedEOF", SKIP); + expectedProblemAttributes.put("PolymorphicMethodNotBelow17", SKIP); expectedProblemAttributes.put("PossibleAccidentalBooleanAssignment", new ProblemAttributes(JavaCore.COMPILER_PB_POSSIBLE_ACCIDENTAL_BOOLEAN_ASSIGNMENT)); + expectedProblemAttributes.put("PotentialHeapPollutionFromVararg", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION)); expectedProblemAttributes.put("PotentialNullLocalVariableReference", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE)); expectedProblemAttributes.put("PublicClassMustMatchFileName", SKIP); expectedProblemAttributes.put("RawMemberTypeCannotBeParameterized", SKIP); @@ -1389,34 +1438,39 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("RecursiveConstructorInvocation", SKIP); expectedProblemAttributes.put("RedefinedArgument", SKIP); expectedProblemAttributes.put("RedefinedLocal", SKIP); + expectedProblemAttributes.put("RedundantSpecificationOfTypeArguments", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_TYPE_ARGUMENTS)); expectedProblemAttributes.put("RedundantLocalVariableNullAssignment", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); expectedProblemAttributes.put("RedundantNullCheckOnNonNullLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); expectedProblemAttributes.put("RedundantNullCheckOnNullLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); expectedProblemAttributes.put("RedundantSuperinterface", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_SUPERINTERFACE)); expectedProblemAttributes.put("ReferenceToForwardField", SKIP); expectedProblemAttributes.put("ReferenceToForwardTypeVariable", SKIP); + expectedProblemAttributes.put("ResourceHasToImplementAutoCloseable", SKIP); expectedProblemAttributes.put("ReturnTypeAmbiguous", SKIP); expectedProblemAttributes.put("ReturnTypeCannotBeVoidArray", SKIP); expectedProblemAttributes.put("ReturnTypeInheritedNameHidesEnclosingName", SKIP); expectedProblemAttributes.put("ReturnTypeInternalNameProvided", SKIP); expectedProblemAttributes.put("ReturnTypeNotFound", SKIP); expectedProblemAttributes.put("ReturnTypeNotVisible", SKIP); + expectedProblemAttributes.put("SafeVarargsOnFixedArityMethod", SKIP); + expectedProblemAttributes.put("SafeVarargsOnNonFinalInstanceMethod", SKIP); expectedProblemAttributes.put("ShouldImplementHashcode", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_HASHCODE_METHOD)); expectedProblemAttributes.put("ShouldReturnValue", SKIP); expectedProblemAttributes.put("StaticInheritedMethodConflicts", SKIP); expectedProblemAttributes.put("StaticMemberOfParameterizedType", SKIP); expectedProblemAttributes.put("StaticMethodRequested", SKIP); expectedProblemAttributes.put("StringConstantIsExceedingUtf8Limit", SKIP); - expectedProblemAttributes.put("SuperclassAmbiguous", SKIP); + expectedProblemAttributes.put("SuperInterfaceMustBeAnInterface", SKIP); + expectedProblemAttributes.put("SuperInterfacesCollide", SKIP); + expectedProblemAttributes.put("SuperTypeUsingWildcard", SKIP); + expectedProblemAttributes.put("SuperclassAmbiguous", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_HASHCODE_METHOD)); expectedProblemAttributes.put("SuperclassInheritedNameHidesEnclosingName", SKIP); expectedProblemAttributes.put("SuperclassInternalNameProvided", SKIP); expectedProblemAttributes.put("SuperclassMustBeAClass", SKIP); expectedProblemAttributes.put("SuperclassNotFound", SKIP); expectedProblemAttributes.put("SuperclassNotVisible", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_SUPERINTERFACE)); expectedProblemAttributes.put("SuperfluousSemicolon", new ProblemAttributes(JavaCore.COMPILER_PB_EMPTY_STATEMENT)); - expectedProblemAttributes.put("SuperInterfaceMustBeAnInterface", SKIP); - expectedProblemAttributes.put("SuperInterfacesCollide", SKIP); - expectedProblemAttributes.put("SuperTypeUsingWildcard", SKIP); + expectedProblemAttributes.put("SwitchOnStringsNotBelow17", SKIP); expectedProblemAttributes.put("Task", SKIP); expectedProblemAttributes.put("ThisInStaticContext", SKIP); expectedProblemAttributes.put("ThisSuperDuringConstructorInvocation", SKIP); @@ -1450,12 +1504,14 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("UndefinedName", SKIP); expectedProblemAttributes.put("UndefinedType", SKIP); expectedProblemAttributes.put("UndefinedTypeVariable", SKIP); + expectedProblemAttributes.put("UnderscoresInLiteralsNotBelow17", SKIP); expectedProblemAttributes.put("UndocumentedEmptyBlock", new ProblemAttributes(JavaCore.COMPILER_PB_UNDOCUMENTED_EMPTY_BLOCK)); expectedProblemAttributes.put("UnexpectedStaticModifierForField", SKIP); expectedProblemAttributes.put("UnexpectedStaticModifierForMethod", SKIP); expectedProblemAttributes.put("UnhandledException", SKIP); expectedProblemAttributes.put("UnhandledExceptionInDefaultConstructor", SKIP); expectedProblemAttributes.put("UnhandledExceptionInImplicitConstructorCall", SKIP); + expectedProblemAttributes.put("UnhandledExceptionOnAutoClose", SKIP); expectedProblemAttributes.put("UnhandledWarningToken", new ProblemAttributes(JavaCore.COMPILER_PB_UNHANDLED_WARNING_TOKEN)); expectedProblemAttributes.put("UninitializedBlankFinalField", SKIP); expectedProblemAttributes.put("UninitializedLocalVariable", SKIP); @@ -1516,6 +1572,13 @@ public void test012_compiler_problems_tuning() { fields = IProblem.class.getFields(); StringBuffer failures = new StringBuffer(); StringBuffer correctResult = new StringBuffer(70000); + Arrays.sort(fields, new Comparator() { + public int compare(Object o1, Object o2) { + Field field1 = (Field) o1; + Field field2 = (Field) o2; + return field1.getName().compareTo(field2.getName()); + } + }); for (int i = 0, length = fields.length; i < length; i++) { Field field = fields[i]; if (field.getType() == Integer.TYPE) { diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java index 3d490fbd4b..2bdc42de5a 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -2727,12 +2727,12 @@ public void test085() { "1. ERROR in A.java (at line 1)\n" + " import static j.l.S.*;\n" + " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, static imports are only available if source level is 1.5\n" + + "Syntax error, static imports are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in A.java (at line 2)\n" + " import static j.l.S.in;\n" + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, static imports are only available if source level is 1.5\n" + + "Syntax error, static imports are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in A.java (at line 2)\n" + " import static j.l.S.in;\n" + @@ -2766,7 +2766,7 @@ public void test086() { "1. ERROR in X.java (at line 1)\n" + " import static p.S;\n" + " ^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, static imports are only available if source level is 1.5\n" + + "Syntax error, static imports are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 5)\n" + " System.out.print(full+\" \"+p.S.success);\n" + @@ -2796,7 +2796,7 @@ public void test087() { "1. ERROR in X.java (at line 1)\n" + " import static S;\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, static imports are only available if source level is 1.5\n" + + "Syntax error, static imports are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 5)\n" + " System.out.print(full+\" \"+S.success);\n" + @@ -2890,7 +2890,7 @@ public void test089() { "1. ERROR in X.java (at line 2)\n" + " @interface I1 {}\n" + " ^^\n" + - "Syntax error, annotation declarations are only available if source level is 1.5\n" + + "Syntax error, annotation declarations are only available if source level is 1.5 or greater\n" + "----------\n"); } //78104 diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java index 2bbc5889cd..16c9fc6046 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -2754,12 +2754,12 @@ public void test085() { "1. ERROR in A.java (at line 1)\n" + " import static j.l.S.*;\n" + " ^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, static imports are only available if source level is 1.5\n" + + "Syntax error, static imports are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in A.java (at line 2)\n" + " import static j.l.S.in;\n" + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, static imports are only available if source level is 1.5\n" + + "Syntax error, static imports are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in A.java (at line 2)\n" + " import static j.l.S.in;\n" + @@ -2793,7 +2793,7 @@ public void test086() { "1. ERROR in X.java (at line 1)\n" + " import static p.S;\n" + " ^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, static imports are only available if source level is 1.5\n" + + "Syntax error, static imports are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 5)\n" + " System.out.print(full+\" \"+p.S.success);\n" + @@ -2823,7 +2823,7 @@ public void test087() { "1. ERROR in X.java (at line 1)\n" + " import static S;\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, static imports are only available if source level is 1.5\n" + + "Syntax error, static imports are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 1)\n" + " import static S;\n" + @@ -2927,7 +2927,7 @@ public void test089() { "1. ERROR in X.java (at line 2)\r\n" + " @interface I1 {}\r\n" + " ^^\n" + - "Syntax error, annotation declarations are only available if source level is 1.5\n" + + "Syntax error, annotation declarations are only available if source level is 1.5 or greater\n" + "----------\n"); } //78104 diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java index 9bb37974b4..77eec90e11 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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,6 +19,7 @@ import org.eclipse.jdt.core.ToolFactory; import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; import org.eclipse.jdt.core.tests.util.Util; import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; public class Compliance_1_5 extends AbstractComparableTest { @@ -2214,6 +2215,37 @@ public void test066() { * Check that indirect member type allocation is denied access to compatible enclosing instance available as constructor argument */ public void test067() { + String expectedError = + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " super(null); //1\n" + + " ^^^^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " super(new M());//2\n" + + " ^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " super(new M());//2\n" + + " ^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"; + if (this.complianceLevel >= ClassFileConstants.JDK1_6) { + expectedError = + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " super(null); //1\n" + + " ^^^^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " super(new M());//2\n" + + " ^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"; + } this.runNegativeTest( new String[] { "X.java", @@ -2235,22 +2267,7 @@ public void test067() { " }\n" + "}\n", }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " super(null); //1\n" + - " ^^^^^^^^^^^^\n" + - "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + - "----------\n" + - "2. ERROR in X.java (at line 14)\n" + - " super(new M());//2\n" + - " ^^^^^^^^^^^^^^^\n" + - "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + - "----------\n" + - "3. ERROR in X.java (at line 14)\n" + - " super(new M());//2\n" + - " ^^^^^^^\n" + - "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + - "----------\n"); + expectedError); } /* @@ -2287,6 +2304,37 @@ public void test068() { * Check that indirect member type allocation is denied access to compatible enclosing instance available as constructor argument */ public void test069() { + String expectedError = + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(new MX4()); // ko\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " super(new MX4()); // ko\n" + + " ^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " this(new MX4()); // ko\n" + + " ^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"; + if (this.complianceLevel >= ClassFileConstants.JDK1_6) { + expectedError = + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(new MX4()); // ko\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " this(new MX4()); // ko\n" + + " ^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"; + } this.runNegativeTest( new String[] { "X.java", @@ -2308,22 +2356,7 @@ public void test069() { " }\n" + "}\n", }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " super(new MX4()); // ko\n" + - " ^^^^^^^^^^^^^^^^^\n" + - "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " super(new MX4()); // ko\n" + - " ^^^^^^^^^\n" + - "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + - "----------\n" + - "3. ERROR in X.java (at line 14)\n" + - " this(new MX4()); // ko\n" + - " ^^^^^^^^^\n" + - "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + - "----------\n"); + expectedError); } // binary compatibility diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_7.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_7.java new file mode 100644 index 0000000000..9cc2b26ac4 --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_7.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2011 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 + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +public class Compliance_1_7 extends AbstractComparableTest { + +public Compliance_1_7(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_7); +} +static { +// Names of tests to run: can be "testBugXXXX" or "BugXXXX") +// TESTS_NAMES = new String[] { "Bug58069" }; +// Numbers of tests to run: "test<number>" will be run for each number of this array +// TESTS_NUMBERS = new int[] { 104 }; +// Range numbers of tests to run: all tests between "test<first>" and "test<last>" will be run for { first, last } +// TESTS_RANGE = new int[] { 85, -1 }; +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=283225 +public void test1() { + this.runConformTest( + new String[] { + "p1/Z.java", + "package p1;\n" + + "import java.util.List;\n" + + "public class Z {\n" + + " @SafeVarargs\n" + + " public static <T> List<T> asList(T... a) {\n" + + " return null;\n" + + " }\n" + + "}" + }, + ""); // no special vm args + + String computedReferences = findReferences(OUTPUT_DIR + "/p1/Z.class"); + boolean check = computedReferences.indexOf("annotationRef/SafeVarargs") >= 0; + if (!check){ + System.out.println(computedReferences); + } + assertTrue("did not indexed the reference to SafeVarargs", check); +} +public void test2() { + this.runConformTest( + new String[] { + "p2/Z.java", + "package p2;\n" + + "import java.lang.annotation.Inherited;\n" + + "@Inherited\n" + + "public @interface Z {\n" + + "}" + }, + ""); // no special vm args + + String computedReferences = findReferences(OUTPUT_DIR + "/p2/Z.class"); + boolean check = computedReferences.indexOf("annotationRef/Inherited") >= 0; + if (!check){ + System.out.println(computedReferences); + } + assertTrue("did not indexed the reference to Inherited", check); +} +public static Class testClass() { + return Compliance_1_7.class; +} +} diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConstantTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConstantTest.java index fbb9f44897..66eeb0d6cb 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConstantTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConstantTest.java @@ -42,7 +42,7 @@ public ConstantTest(String name) { static { // TESTS_PREFIX = "testBug95521"; // TESTS_NAMES = new String[] { "testBug83127a" }; -// TESTS_NUMBERS = new int[] { 14, 15, 16 }; +// TESTS_NUMBERS = new int[] { 21 }; // TESTS_RANGE = new int[] { 23, -1 }; } public static Test suite() { @@ -330,6 +330,10 @@ public void test008() { * null is not a constant * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26138 */ +/* + * null is not a constant + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26138 + */ public void test009() throws Exception { this.runConformTest( new String[] { @@ -1415,6 +1419,102 @@ private void verifyConstantEqualsAndHashcode( assertFalse("Have same values", ((Constant) o).hasSameValue((Constant) o4)); } } +//test corner values (max, min, -1) for longs +public void test021() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0x0L); // OK\n" + + " System.out.println(0x8000000000000000L); // OK\n" + + " System.out.println(0x8000000000000000l); // OK\n" + + " System.out.println(01000000000000000000000L); // OK\n" + + " System.out.println(01000000000000000000000l); // OK\n" + + " System.out.println(-9223372036854775808L); // OK\n" + + " System.out.println(-9223372036854775808l); // OK\n" + + " System.out.println(0x7fffffffffffffffL); // OK\n" + + " System.out.println(0x7fffffffffffffffl); // OK\n" + + " System.out.println(0777777777777777777777L); // OK\n" + + " System.out.println(0777777777777777777777l); // OK\n" + + " System.out.println(9223372036854775807L); // OK\n" + + " System.out.println(9223372036854775807l); // OK\n" + + " System.out.println(0xffffffffffffffffL); // OK\n" + + " System.out.println(0x0000000000000ffffffffffffffffL); // OK\n" + + " System.out.println(0xffffffffffffffffl); // OK\n" + + " System.out.println(01777777777777777777777L); // OK\n" + + " System.out.println(01777777777777777777777l); // OK\n" + + " System.out.println(-0x1L); // OK\n" + + " System.out.println(-0x1l); // OK\n" + + " System.out.println(0677777777777777777777L);\n" + + " System.out.println(0677777777777777777777l);\n" + + " System.out.println(0x0000000000000L); // OK\n" + + " System.out.println(0L); // OK\n" + + " }\n" + + "}", + }, + "0\n" + + "-9223372036854775808\n" + + "-9223372036854775808\n" + + "-9223372036854775808\n" + + "-9223372036854775808\n" + + "-9223372036854775808\n" + + "-9223372036854775808\n" + + "9223372036854775807\n" + + "9223372036854775807\n" + + "9223372036854775807\n" + + "9223372036854775807\n" + + "9223372036854775807\n" + + "9223372036854775807\n" + + "-1\n" + + "-1\n" + + "-1\n" + + "-1\n" + + "-1\n" + + "-1\n" + + "-1\n" + + "8070450532247928831\n" + + "8070450532247928831\n" + + "0\n" + + "0"); +} +//test corner values (max, min, -1) for ints +public void test022() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0x0); // OK\n" + + " System.out.println(0x80000000); // OK\n" + + " System.out.println(020000000000); // OK\n" + + " System.out.println(-2147483648); // OK\n" + + " System.out.println(0x7fffffff); // OK\n" + + " System.out.println(017777777777); // OK\n" + + " System.out.println(2147483647); // OK\n" + + " System.out.println(0xffffffff); // OK\n" + + " System.out.println(0x0000000000000ffffffff); // OK\n" + + " System.out.println(037777777777); // OK\n" + + " System.out.println(-0x1); // OK\n" + + " System.out.println(0xDADACAFE);\n" + + " System.out.println(0x0000000000000); // OK\n" + + " }\n" + + "}", + }, + "0\n" + + "-2147483648\n" + + "-2147483648\n" + + "-2147483648\n" + + "2147483647\n" + + "2147483647\n" + + "2147483647\n" + + "-1\n" + + "-1\n" + + "-1\n" + + "-1\n" + + "-623195394\n" + + "0"); +} public static Class testClass() { return ConstantTest.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 7cc4ecb2dd..f45f276f43 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 @@ -4,7 +4,7 @@ * 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 *******************************************************************************/ @@ -15,6 +15,7 @@ import java.util.Map; import junit.framework.Test; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.ToolFactory; import org.eclipse.jdt.core.tests.util.Util; import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; @@ -30,8 +31,8 @@ public class GenericTypeTest 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[] { "test1203c", "test1203d" }; -// TESTS_NUMBERS = new int[] { 1465 }; +// TESTS_NAMES = new String[] { "test1404" }; +// TESTS_NUMBERS = new int[] { 593, 701, 746, 848, 953, 985, 1029, 1136, 1227, 1295, 1341 }; // TESTS_RANGE = new int[] { 1097, -1 }; } public static Test suite() { @@ -11754,12 +11755,24 @@ public class GenericTypeTest extends AbstractComparableTest { " }\n" + "}\n" }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. ERROR in X.java (at line 4)\n" + " String[] s = foo(null, new String[]{ \"hello\" });\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type mismatch: cannot convert from String to String[]\n" + - "----------\n" + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " String[] s = foo(null, new String[]{ \"hello\" });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from String to String[]\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " public <F> F foo(F f, F... others) {\n" + + " ^^^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter others\n" + + "----------\n" ); } @@ -12422,12 +12435,24 @@ public class GenericTypeTest extends AbstractComparableTest { " Zork z;\n" + "}", }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. ERROR in X.java (at line 15)\n" + " Zork z;\n" + " ^^^^\n" + "Zork cannot be resolved to a type\n" + - "----------\n"); + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static <T> T first(T... args) {\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter args\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78467 - variation public void test0412a() { @@ -12452,17 +12477,34 @@ public class GenericTypeTest extends AbstractComparableTest { " Zork z;\n" + "}", }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. WARNING in X.java (at line 10)\n" + " List<String> ls = first(); \n" + " ^^^^^^^\n" + - "Type safety : A generic array of List<String> is created for a varargs parameter\n" + + "Type safety: A generic array of List<String> is created for a varargs parameter\n" + "----------\n" + "2. ERROR in X.java (at line 16)\n" + " Zork z;\n" + " ^^^^\n" + "Zork cannot be resolved to a type\n" + - "----------\n"); + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public static <T> T first(T... args) {\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter args\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " List<String> ls = first(); \n" + + " ^^^^^^^\n" + + "Type safety: A generic array of List<String> is created for a varargs parameter\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); } public void test0413() { @@ -12692,7 +12734,7 @@ public class GenericTypeTest extends AbstractComparableTest { } public void test0423() { - this.runNegativeTest( + this.runConformTest( new String[] { "X.java", "public class X {\n" + @@ -12711,12 +12753,7 @@ public class GenericTypeTest extends AbstractComparableTest { "\n" + "}", }, - "----------\n" + - "1. ERROR in X.java (at line 12)\n" + - " foo();\n" + - " ^^^\n" + - "Bound mismatch: The generic method foo() of type X is not applicable for the arguments (). The inferred type X is not a valid substitute for the bounded parameter <U extends X & Runnable>\n" + - "----------\n"); + ""); } public void test0424() { @@ -18516,6 +18553,8 @@ X.java:6: name clash: <T#1>foo(Object) and <T#2>foo(Object) have the same erasur ""); } public void test0593() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE); this.runNegativeTest( new String[] { "X.java", @@ -18526,21 +18565,14 @@ X.java:6: name clash: <T#1>foo(Object) and <T#2>foo(Object) have the same erasur "}\n", }, "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " List<Class<?>> classes1 = Arrays.asList(String.class, Boolean.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Class<? extends Object&Serializable&Comparable<?>> is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + + "1. ERROR in X.java (at line 3)\n" + " List<Class<?>> classes1 = Arrays.asList(String.class, Boolean.class);\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type mismatch: cannot convert from List<Class<? extends Object&Serializable&Comparable<?>>> to List<Class<?>>\n" + - "----------\n" + - "3. WARNING in X.java (at line 4)\n" + - " List<? extends Class<?>> classes2 = Arrays.asList(String.class, Boolean.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Class<? extends Object&Serializable&Comparable<?>> is created for a varargs parameter\n" + - "----------\n"); + "----------\n", + null, + true, + options); } public void test0594() { this.runNegativeTest( @@ -22231,6 +22263,8 @@ public void test0700() { } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=97303 public void test0701() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE); this.runNegativeTest( new String[] { "X.java", @@ -22253,26 +22287,14 @@ public void test0701() { "class Song {}\n", }, "----------\n" + - "1. WARNING in X.java (at line 10)\n" + - " List<Counter<?>> list1 = Arrays.asList(songCounter, genreCounter);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Deejay.Counter<? extends Object> is created for a varargs parameter\n" + - "----------\n" + - "2. WARNING in X.java (at line 11)\n" + - " List<Counter<? extends Object>> list2 = Arrays.asList(songCounter, genreCounter);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Deejay.Counter<? extends Object> is created for a varargs parameter\n" + - "----------\n" + - "3. WARNING in X.java (at line 14)\n" + - " List<Counter<? extends String>> list5 = Arrays.asList(songCounter, genreCounter);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Deejay.Counter<? extends Object> is created for a varargs parameter\n" + - "----------\n" + - "4. ERROR in X.java (at line 14)\n" + + "1. ERROR in X.java (at line 14)\n" + " List<Counter<? extends String>> list5 = Arrays.asList(songCounter, genreCounter);\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type mismatch: cannot convert from List<Deejay.Counter<? extends Object>> to List<Deejay.Counter<? extends String>>\n" + - "----------\n"); + "----------\n", + null, + true, + options); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=97303 - variation public void test0702() { @@ -23714,6 +23736,8 @@ public void test0745() { } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99922 - variation public void test0746() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE); this.runNegativeTest( new String[] { "X.java", @@ -23724,16 +23748,14 @@ public void test0746() { "}\n" }, "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " String s = java.util.Arrays.asList(3, 3.1);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Number&Comparable<?> is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + + "1. ERROR in X.java (at line 3)\n" + " String s = java.util.Arrays.asList(3, 3.1);\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type mismatch: cannot convert from List<Number&Comparable<?>> to String\n" + - "----------\n"); + "----------\n", + null, + true, + options); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99983 public void test0747() { @@ -25300,12 +25322,24 @@ public void test0798() { " }\n" + "}\n", }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. ERROR in X.java (at line 16)\n" + " System.out.println(max(1, 2.0, new BigDecimal(Math.PI)));\n" + " ^^^\n" + "Bound mismatch: The generic method max(T...) of type X is not applicable for the arguments (Integer, Double, BigDecimal). The inferred type Number&Comparable<?> is not a valid substitute for the bounded parameter <T extends Comparable<? super T>>\n" + - "----------\n"); + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " private static <T extends Comparable<? super T>> T max(T... elems)\n" + + " ^^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter elems\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " System.out.println(max(1, 2.0, new BigDecimal(Math.PI)));\n" + + " ^^^\n" + + "Bound mismatch: The generic method max(T...) of type X is not applicable for the arguments (Integer, Double, BigDecimal). The inferred type Number&Comparable<?> is not a valid substitute for the bounded parameter <T extends Comparable<? super T>>\n" + + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=105531 public void test0799() { @@ -27181,29 +27215,25 @@ public void test0848() throws Exception { "import java.util.*;\n" + "\n" + "public class X<E> {\n" + - " Collection<? extends Number> asList= Arrays.asList(1, 2.2);\n" + + " public static <T> List<T> asList(T a) { return null; }\n" + + " Collection<? extends Number> asList= asList(1);\n" + " List<Number> nums= (List<Number>) asList; // correct warning\n" + " List<Number> numz= (LinkedList<Number>) asList; // type safety warning missing\n" + " Zork z;\n" + "}\n", // ================= }, "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " Collection<? extends Number> asList= Arrays.asList(1, 2.2);\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Number&Comparable<?> is created for a varargs parameter\n" + - "----------\n" + - "2. WARNING in X.java (at line 5)\n" + + "1. WARNING in X.java (at line 6)\n" + " List<Number> nums= (List<Number>) asList; // correct warning\n" + " ^^^^^^^^^^^^^^^^^^^^^\n" + "Type safety: Unchecked cast from Collection<capture#1-of ? extends Number> to List<Number>\n" + "----------\n" + - "3. WARNING in X.java (at line 6)\n" + + "2. WARNING in X.java (at line 7)\n" + " List<Number> numz= (LinkedList<Number>) asList; // type safety warning missing\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type safety: Unchecked cast from Collection<capture#2-of ? extends Number> to LinkedList<Number>\n" + "----------\n" + - "4. ERROR in X.java (at line 7)\n" + + "3. ERROR in X.java (at line 8)\n" + " Zork z;\n" + " ^^^^\n" + "Zork cannot be resolved to a type\n" + @@ -28354,11 +28384,6 @@ public void test0881() { " String s = (String) Foo.foo();\n" + " ^^^^^^^^^^^^^^^^^^\n" + "Cannot cast from List<List<U>> to String\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + - " String s = (String) Foo.foo();\n" + - " ^^^\n" + - "Bound mismatch: The generic method foo() of type Foo is not applicable for the arguments (). The inferred type List<List<U>> is not a valid substitute for the bounded parameter <U extends List<U>>\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 - variation @@ -30851,27 +30876,59 @@ public void test0949() { " }\n" + "}\n", }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. WARNING in X.java (at line 10)\n" + " m3(m(3, 3, 3));\n" + " ^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterable<Integer> is created for a varargs parameter\n" + + "Type safety: A generic array of Iterable<Integer> is created for a varargs parameter\n" + "----------\n" + "2. WARNING in X.java (at line 11)\n" + " m3(m());\n" + " ^^^^^^^\n" + - "Type safety : A generic array of Iterable<Object> is created for a varargs parameter\n" + + "Type safety: A generic array of Iterable<Object> is created for a varargs parameter\n" + "----------\n" + "3. WARNING in X.java (at line 12)\n" + " m3(m(new Object[]{}));\n" + " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterable<Object> is created for a varargs parameter\n" + + "Type safety: A generic array of Iterable<Object> is created for a varargs parameter\n" + "----------\n" + "4. ERROR in X.java (at line 13)\n" + " Zork z;\n" + " ^^^^\n" + "Zork cannot be resolved to a type\n" + - "----------\n"); + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public <T> Iterable<T> m(T... ts) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter ts\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " public <T> void m3(Iterable<T>... ts) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter ts\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " m3(m(3, 3, 3));\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterable<Integer> is created for a varargs parameter\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " m3(m());\n" + + " ^^^^^^^\n" + + "Type safety: A generic array of Iterable<Object> is created for a varargs parameter\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " m3(m(new Object[]{}));\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterable<Object> is created for a varargs parameter\n" + + "----------\n" + + "6. ERROR in X.java (at line 13)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=128418 - variation public void test0950() { @@ -30894,27 +30951,59 @@ public void test0950() { " }\n" + "}\n", }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. WARNING in X.java (at line 10)\n" + " m3(m(new Integer[]{3, 3, 3}));\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterable<Object> is created for a varargs parameter\n" + + "Type safety: A generic array of Iterable<Object> is created for a varargs parameter\n" + "----------\n" + "2. WARNING in X.java (at line 11)\n" + " m3(m());\n" + " ^^^^^^^\n" + - "Type safety : A generic array of Iterable<Object> is created for a varargs parameter\n" + + "Type safety: A generic array of Iterable<Object> is created for a varargs parameter\n" + "----------\n" + "3. WARNING in X.java (at line 12)\n" + " m3(m(new Object[][]{}));\n" + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterable<Object> is created for a varargs parameter\n" + + "Type safety: A generic array of Iterable<Object> is created for a varargs parameter\n" + "----------\n" + "4. ERROR in X.java (at line 13)\n" + " Zork z;\n" + " ^^^^\n" + "Zork cannot be resolved to a type\n" + - "----------\n"); + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public <T> Iterable<T> m(T[]... ts) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter ts\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " public <T> void m3(Iterable<T>... ts) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter ts\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " m3(m(new Integer[]{3, 3, 3}));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterable<Object> is created for a varargs parameter\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " m3(m());\n" + + " ^^^^^^^\n" + + "Type safety: A generic array of Iterable<Object> is created for a varargs parameter\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " m3(m(new Object[][]{}));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterable<Object> is created for a varargs parameter\n" + + "----------\n" + + "6. ERROR in X.java (at line 13)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=128418 - variation public void test0951() { @@ -30938,12 +31027,29 @@ public void test0951() { " }\n" + "}\n", }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. ERROR in X.java (at line 14)\n" + " Zork z;\n" + " ^^^^\n" + "Zork cannot be resolved to a type\n" + - "----------\n"); + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public <T> Iterable<T> m(T[]... ts) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter ts\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " public <T> void m3(Iterable<T>... ts) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter ts\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=128418 - variation public void test0952() { @@ -30962,11 +31068,12 @@ public void test0952() { " }\n" + "}\n", }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. WARNING in X.java (at line 8)\n" + " m3(m(null));\n" + " ^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterable<Object> is created for a varargs parameter\n" + + "Type safety: A generic array of Iterable<Object> is created for a varargs parameter\n" + "----------\n" + "2. WARNING in X.java (at line 8)\n" + " m3(m(null));\n" + @@ -30977,10 +31084,37 @@ public void test0952() { " Zork z;\n" + " ^^^^\n" + "Zork cannot be resolved to a type\n" + - "----------\n"); + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public <T> Iterable<T> m(T... ts) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter ts\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " public <T> void m3(Iterable<T>... ts) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter ts\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " m3(m(null));\n" + + " ^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterable<Object> is created for a varargs parameter\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " m3(m(null));\n" + + " ^^^^^^^\n" + + "The argument of type null should explicitly be cast to Object[] for the invocation of the varargs method m(Object...) from type X. It could alternatively be cast to Object for a varargs invocation\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=106325 public void test0953() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) return; this.runNegativeTest( new String[] { "X.java", //================================ @@ -30999,7 +31133,7 @@ public void test0953() { "1. WARNING in X.java (at line 7)\n" + " List<WeakReference<Integer>> list= Arrays.asList(ref);\n" + " ^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of WeakReference<Integer> is created for a varargs parameter\n" + + "Type safety: A generic array of WeakReference<Integer> is created for a varargs parameter\n" + "----------\n" + "2. ERROR in X.java (at line 8)\n" + " Zork z;\n" + @@ -31280,17 +31414,12 @@ public void test0960() { " ^\n" + "X is a raw type. References to generic type X<A> should be parameterized\n" + "----------\n" + - "2. ERROR in X.java (at line 7)\n" + - " X x = newInstance();\n" + - " ^^^^^^^^^^^\n" + - "Bound mismatch: The generic method newInstance() of type X<A> is not applicable for the arguments (). The inferred type Comparable<Comparable<B>> is not a valid substitute for the bounded parameter <B extends Comparable<B>>\n" + - "----------\n" + - "3. WARNING in X.java (at line 8)\n" + + "2. WARNING in X.java (at line 8)\n" + " return new X[] { x };\n" + " ^^^^^^^^^^^^^\n" + "Type safety: The expression of type X[] needs unchecked conversion to conform to X<String>[]\n" + "----------\n" + - "4. ERROR in X.java (at line 10)\n" + + "3. ERROR in X.java (at line 10)\n" + " Zork z;\n" + " ^^^^\n" + "Zork cannot be resolved to a type\n" + @@ -32118,6 +32247,8 @@ public void test0984() { } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=141330 public void test0985() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE); this.runNegativeTest( new String[] { "X.java", // ================= @@ -32129,16 +32260,14 @@ public void test0985() { "}\n", // ================= }, "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " List<Class<Object>> lco = Arrays.asList(String.class, Integer.class, Long.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Class<? extends Object&Serializable&Comparable<?>> is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + + "1. ERROR in X.java (at line 4)\n" + " List<Class<Object>> lco = Arrays.asList(String.class, Integer.class, Long.class);\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type mismatch: cannot convert from List<Class<? extends Object&Serializable&Comparable<?>>> to List<Class<Object>>\n" + - "----------\n"); + "----------\n", + null, + true, + options); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=91709 public void test0986() { @@ -32211,22 +32340,32 @@ public void test0986() { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643 public void test0987() { String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 - ? "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " public ISheetViewer getViewer() { return null; } \n" + - " ^^^^^^^^^^^^\n" + - "The return type is incompatible with EditPart.getViewer()\n" + - "----------\n" + - "2. ERROR in X.java (at line 11)\n" + - " public ISheetViewer getViewer() { return null; } \n" + - " ^^^^^^^^^^^\n" + - "The method getViewer() of type AbstractLinkView<M> must override a superclass method\n" + + ? "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " abstract class GLinkElementView<M,CM> extends AbstractLinkView<M> {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return types are incompatible for the inherited methods EditPart.getViewer(), AbstractLinkView<M>.getViewer()\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " public ISheetViewer getViewer() { return null; } \n" + + " ^^^^^^^^^^^^\n" + + "The return type is incompatible with EditPart.getViewer()\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " public ISheetViewer getViewer() { return null; } \n" + + " ^^^^^^^^^^^\n" + + "The method getViewer() of type AbstractLinkView<M> must override a superclass method\n" + "----------\n" - : "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " public ISheetViewer getViewer() { return null; } \n" + - " ^^^^^^^^^^^^\n" + - "The return type is incompatible with EditPart.getViewer()\n" + + : "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " abstract class GLinkElementView<M,CM> extends AbstractLinkView<M> {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return types are incompatible for the inherited methods EditPart.getViewer(), AbstractLinkView<M>.getViewer()\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " public ISheetViewer getViewer() { return null; } \n" + + " ^^^^^^^^^^^^\n" + + "The return type is incompatible with EditPart.getViewer()\n" + "----------\n"; this.runNegativeTest( new String[] { @@ -32311,11 +32450,16 @@ public void test0988() { " public ISheetViewer getViewer();\n" + "}", // ================= }, - "----------\n" + - "1. ERROR in X.java (at line 11)\n" + - " public SheetViewer getViewer() { return null; } \n" + - " ^^^^^^^^^^^\n" + - "The return type is incompatible with AbstractEditPart.getViewer()\n" + + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " abstract class GLinkElementView<M,CM> extends AbstractLinkView<M> {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return types are incompatible for the inherited methods EditPart.getViewer(), ILinkViewElement.getViewer(), AbstractLinkView<M>.getViewer()\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " public SheetViewer getViewer() { return null; } \n" + + " ^^^^^^^^^^^\n" + + "The return type is incompatible with AbstractEditPart.getViewer()\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 @@ -32650,6 +32794,7 @@ public void test0999() { " }\n" + "}", // ================= }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. WARNING in X.java (at line 9)\n" + " Iterator<Number> it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + @@ -32674,8 +32819,39 @@ public void test0999() { "5. WARNING in X.java (at line 18)\n" + " Iterator<Number> it2 = X.chain(l1.iterator(), l1.iterator());\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterator<Integer> is created for a varargs parameter\n" + - "----------\n"); + "Type safety: A generic array of Iterator<Integer> is created for a varargs parameter\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static final <T,E extends T> Iterator<T> chain(Iterator<E>... it) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter it\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " Iterator<Number> it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation chain(Iterator[]) of the generic method chain(Iterator<E>...) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " Iterator<Number> it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator<Number>\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " Iterator<Number> it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Iterator[] needs unchecked conversion to conform to Iterator<Number>[]\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " Iterator<Number> it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^\n" + + "The method chain(Iterator<E>...) in the type X is not applicable for the arguments (Iterator<Integer>, Iterator<Float>)\n" + + "----------\n" + + "6. WARNING in X.java (at line 18)\n" + + " Iterator<Number> it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterator<Integer> is created for a varargs parameter\n" + + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=144879 public void test1000() { @@ -32703,6 +32879,7 @@ public void test1000() { " }\n" + "}", // ================= }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. WARNING in X.java (at line 9)\n" + " Iterator<Number> it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + @@ -32722,7 +32899,7 @@ public void test1000() { "4. WARNING in X.java (at line 14)\n" + " Iterator<Number> it2 = X.chain(l1.iterator(), l2.iterator());\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterator<? extends Number&Comparable<?>> is created for a varargs parameter\n" + + "Type safety: A generic array of Iterator<? extends Number&Comparable<?>> is created for a varargs parameter\n" + "----------\n" + "5. ERROR in X.java (at line 14)\n" + " Iterator<Number> it2 = X.chain(l1.iterator(), l2.iterator());\n" + @@ -32732,13 +32909,54 @@ public void test1000() { "6. WARNING in X.java (at line 18)\n" + " Iterator<Number> it2 = X.chain(l1.iterator(), l1.iterator());\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Iterator<? extends Integer> is created for a varargs parameter\n" + + "Type safety: A generic array of Iterator<? extends Integer> is created for a varargs parameter\n" + "----------\n" + "7. ERROR in X.java (at line 18)\n" + " Iterator<Number> it2 = X.chain(l1.iterator(), l1.iterator());\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type mismatch: cannot convert from Iterator<Integer> to Iterator<Number>\n" + - "----------\n"); + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static final <T> Iterator<T> chain(Iterator<? extends T>... it) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter it\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " Iterator<Number> it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation chain(Iterator[]) of the generic method chain(Iterator<? extends T>...) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " Iterator<Number> it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator<Number>\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " Iterator<Number> it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Iterator[] needs unchecked conversion to conform to Iterator<? extends Number>[]\n" + + "----------\n" + + "5. WARNING in X.java (at line 14)\n" + + " Iterator<Number> it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterator<? extends Number&Comparable<?>> is created for a varargs parameter\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " Iterator<Number> it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator<Number&Comparable<?>> to Iterator<Number>\n" + + "----------\n" + + "7. WARNING in X.java (at line 18)\n" + + " Iterator<Number> it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterator<? extends Integer> is created for a varargs parameter\n" + + "----------\n" + + "8. ERROR in X.java (at line 18)\n" + + " Iterator<Number> it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator<Integer> to Iterator<Number>\n" + + "----------\n"); } public void test1001() { this.runConformTest( @@ -33716,6 +33934,7 @@ public void test1027() { // test directory preparation new String[] { /* test files */ "X.java", + this.complianceLevel < ClassFileConstants.JDK1_7 ? "import java.util.LinkedHashSet;\n" + "import java.util.Set;\n" + "\n" + @@ -33736,7 +33955,29 @@ public void test1027() { " return set;\n" + " }\n" + "}\n" + - "\n", // ================= + "\n" : + "import java.util.LinkedHashSet;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public class A {};\n" + + " public class B extends A {};\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X g = new X();\n" + + " Set<A> set = g.newSet(g.new B());\n" + + " }\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public <T, V extends T> Set<T> newSet(V... objects) {\n" + + " Set<T> set = new LinkedHashSet<T>();\n" + + " for (T t : objects) {\n" + + " set.add(t);\n" + + " }\n" + + " return set;\n" + + " }\n" + + "}\n" + + "\n", // =================, // ================= }, // javac options JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); @@ -33771,6 +34012,8 @@ public void test1028() { } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=156016 public void test1029() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE); this.runNegativeTest( new String[] { "X.java", @@ -33788,16 +34031,14 @@ public void test1029() { "}", // ================= }, "----------\n" + - "1. WARNING in X.java (at line 6)\n" + - " return Arrays.asList(a, b);\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of T is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 10)\n" + + "1. ERROR in X.java (at line 10)\n" + " List<Number> name = makeNumberList(5, 5D);\n" + " ^^^^^^^^^^^^^^^^^^^^^\n" + "Type mismatch: cannot convert from List<Number&Comparable<?>> to List<Number>\n" + - "----------\n"); + "----------\n", + null, + true, + options); } public void test1030() { this.runConformTest( @@ -34114,16 +34355,6 @@ public void test1035() { " static <M extends String> Comparator<M> baz() {\n" + " ^^^^^^\n" + "The type parameter M should not be bounded by the final type String. Final types cannot be further extended\n" + - "----------\n" + - "2. ERROR in ComparableComparator.java (at line 25)\n" + - " static Comparator BAR = ComparableComparator.bar();//0\n" + - " ^^^\n" + - "Bound mismatch: The generic method bar() of type ComparableComparator<T> is not applicable for the arguments (). The inferred type Comparable<Comparable<M>> is not a valid substitute for the bounded parameter <M extends Comparable<M>>\n" + - "----------\n" + - "3. ERROR in ComparableComparator.java (at line 27)\n" + - " static Object BAR2 = ComparableComparator.bar();//1a\n" + - " ^^^\n" + - "Bound mismatch: The generic method bar() of type ComparableComparator<T> is not applicable for the arguments (). The inferred type Comparable<Comparable<M>> is not a valid substitute for the bounded parameter <M extends Comparable<M>>\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=158548 @@ -37197,7 +37428,13 @@ public void test1099() { "}\n" }, // compiler results - "" /* expected compiler log */, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "" : + "----------\n" + + "1. WARNING in X.java (at line 21)\n" + + " public <U, V extends U> List<U> newList(V... values) {\n" + + " ^^^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter values\n" + + "----------\n", // runtime results "SUCCESS" /* expected output string */, "" /* expected error string */, @@ -38581,6 +38818,8 @@ public void test1135() { } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=154029 public void test1136() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE); this.runNegativeTest( new String[] { "X.java", @@ -38600,26 +38839,19 @@ public void test1136() { "class C<T> extends A<T> implements I {}\n", // ================= }, "----------\n" + - "1. WARNING in X.java (at line 4)\n" + - " List<Object> l1 = Arrays.asList(1, \"X\");\n" + - " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Object&Comparable<?>&Serializable is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 4)\n" + + "1. ERROR in X.java (at line 4)\n" + " List<Object> l1 = Arrays.asList(1, \"X\");\n" + " ^^^^^^^^^^^^^^^^^^^^^\n" + "Type mismatch: cannot convert from List<Object&Comparable<?>&Serializable> to List<Object>\n" + "----------\n" + - "3. WARNING in X.java (at line 8)\n" + - " List<Object> l2 = Arrays.asList(b, c);\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of A<String>&I is created for a varargs parameter\n" + - "----------\n" + - "4. ERROR in X.java (at line 8)\n" + + "2. ERROR in X.java (at line 8)\n" + " List<Object> l2 = Arrays.asList(b, c);\n" + " ^^^^^^^^^^^^^^^^^^^\n" + "Type mismatch: cannot convert from List<A<String>&I> to List<Object>\n" + - "----------\n"); + "----------\n", + null, + true, + options); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=154267 public void test1137() { @@ -38898,6 +39130,7 @@ public void test1146() { " } \n" + "}\n", // ================= }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. ERROR in X.java (at line 7)\n" + " int i = asList(a, b, rest);\n" + @@ -38913,7 +39146,33 @@ public void test1146() { " return compound(asList(a, b, rest));\n" + " ^^^^^^^^\n" + "The method compound(Iterable<? extends Comparator<? super U>>) in the type X is not applicable for the arguments (List<Comparator<?>>)\n" + - "----------\n"); + "----------\n": + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Comparator<? super T>... rest) {\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter rest\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " int i = asList(a, b, rest);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List<Comparator<?>> to int\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " int j = asList2(a, b);\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List<Comparator<? extends Object>> to int\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " return compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable<? extends Comparator<? super U>>) in the type X is not applicable for the arguments (List<Comparator<?>>)\n" + + "----------\n" + + "5. WARNING in X.java (at line 14)\n" + + " public static <E> List<E> asList(E a, E b, E... rest) {\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter rest\n" + + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation public void test1147() { @@ -38980,6 +39239,7 @@ public void test1148() { " }\n" + "}\n", // ================= }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. ERROR in X.java (at line 4)\n" + " int i = asList(a, b, rest);\n" + @@ -39010,7 +39270,48 @@ public void test1148() { " return compound(c);\n" + " ^^^^^^^^\n" + "The method compound(Iterable<? extends Comparator<? super U>>) in the type X is not applicable for the arguments (List<Comparator<?>>)\n" + - "----------\n"); + "----------\n": + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static <T> Comparator<T> compound(Comparator<? super T> a, Comparator<? super T> b, Comparator<? super T>... rest) {\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter rest\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " int i = asList(a, b, rest);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List<Comparator<?>> to int\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " int j = compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable<? extends Comparator<? super U>>) in the type X is not applicable for the arguments (List<Comparator<?>>)\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable<? extends Comparator<? super U>>) in the type X is not applicable for the arguments (List<Comparator<?>>)\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " if (true) return compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable<? extends Comparator<? super U>>) in the type X is not applicable for the arguments (List<Comparator<?>>)\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " compound(c);\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable<? extends Comparator<? super U>>) in the type X is not applicable for the arguments (List<Comparator<?>>)\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " return compound(c);\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable<? extends Comparator<? super U>>) in the type X is not applicable for the arguments (List<Comparator<?>>)\n" + + "----------\n" + + "8. WARNING in X.java (at line 16)\n" + + " public static <E> List<E> asList(E a, E b, E... rest) {\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter rest\n" + + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=198051 public void test1149() { @@ -41265,11 +41566,16 @@ public void test1210() { " }\n" + "}\n", // ================= }, - "----------\n" + - "1. ERROR in X.java (at line 6)\n" + - " Object[] o = throwE(objs);\n" + - " ^^^^^^\n" + - "Bound mismatch: The generic method throwE(Object...) of type X is not applicable for the arguments (Object[]). The inferred type Object[] is not a valid substitute for the bounded parameter <E extends Exception>\n" + + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Object[] o = throwE(objs);\n" + + " ^^^^^^\n" + + "Bound mismatch: The generic method throwE(Object...) of type X is not applicable for the arguments (Object[]). The inferred type Object[]&Exception is not a valid substitute for the bounded parameter <E extends Exception>\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Object[] o = throwE(objs);\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object[]&Exception to Object[]\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=208030 @@ -41874,6 +42180,7 @@ public void test1226() { "----------\n"); } public void test1227() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) return; this.runNegativeTest( new String[] { "X.java", @@ -41889,7 +42196,7 @@ public void test1227() { "1. WARNING in X.java (at line 4)\n" + " Arrays.asList(String.class, Integer.class);\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Class<? extends Object&Serializable&Comparable<?>> is created for a varargs parameter\n" + + "Type safety: A generic array of Class<? extends Object&Serializable&Comparable<?>> is created for a varargs parameter\n" + "----------\n" + "2. ERROR in X.java (at line 6)\n" + " Zork z;\n" + @@ -44021,6 +44328,8 @@ public void test1294() { } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=97303 - variation public void test1295() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE); this.runNegativeTest( new String[] { "X.java", @@ -44040,26 +44349,14 @@ public void test1295() { "class Song {}\n", // ================= }, "----------\n" + - "1. WARNING in X.java (at line 7)\n" + - " java.util.List<Counter<?>> list1 = java.util.Arrays.asList(songCounter, genreCounter);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Deejay.Counter<? extends Object> is created for a varargs parameter\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + - " java.util.List<Counter<? extends Object>> list2 = java.util.Arrays.asList(songCounter, genreCounter);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Deejay.Counter<? extends Object> is created for a varargs parameter\n" + - "----------\n" + - "3. WARNING in X.java (at line 11)\n" + - " java.util.List<Counter<? extends String>> list5 = java.util.Arrays.asList(songCounter, genreCounter);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Deejay.Counter<? extends Object> is created for a varargs parameter\n" + - "----------\n" + - "4. ERROR in X.java (at line 11)\n" + + "1. ERROR in X.java (at line 11)\n" + " java.util.List<Counter<? extends String>> list5 = java.util.Arrays.asList(songCounter, genreCounter);\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Type mismatch: cannot convert from List<Deejay.Counter<? extends Object>> to List<Deejay.Counter<? extends String>>\n" + - "----------\n"); + "----------\n", + null, + true, + options); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation public void test1296() { @@ -44823,26 +45120,31 @@ public void test1317() { " }\n" + "}\n", // ================= }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " <T extends N<T>> T foo3(String name, T value) {}\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "This method must return a result of type T\n" + - "----------\n" + - "2. ERROR in X.java (at line 15)\n" + - " new X().foo(\"HI\", null); // correctly report error\n" + - " ^^^\n" + - "The method foo(String, String) is ambiguous for the type X\n" + - "----------\n" + - "3. ERROR in X.java (at line 18)\n" + - " Thread t1 = foo3(\"HI\", null);\n" + - " ^^^^\n" + - "The method foo3(String, null) is undefined for the type Test\n" + - "----------\n" + - "4. ERROR in X.java (at line 19)\n" + - " Thread t2 = (Thread)foo3(\"HI\", null);\n" + - " ^^^^\n" + - "The method foo3(String, null) is undefined for the type Test\n" + + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " <T extends N<T>> T foo3(String name, T value) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "This method must return a result of type T\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " new X().foo(\"HI\", null); // correctly report error\n" + + " ^^^\n" + + "The method foo(String, String) is ambiguous for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " new X().foo2(\"HI\", null); // miss ambiguous error\n" + + " ^^^^\n" + + "The method foo2(String, String) is ambiguous for the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 18)\n" + + " Thread t1 = foo3(\"HI\", null);\n" + + " ^^^^\n" + + "The method foo3(String, null) is undefined for the type Test\n" + + "----------\n" + + "5. ERROR in X.java (at line 19)\n" + + " Thread t2 = (Thread)foo3(\"HI\", null);\n" + + " ^^^^\n" + + "The method foo3(String, null) is undefined for the type Test\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation @@ -44864,17 +45166,12 @@ public void test1318() { "}\n", // ================= }, "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().foo2(\"HI\", null);\n" + - " ^^^^\n" + - "Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N<N<T>> is not a valid substitute for the bounded parameter <T extends N<T>>\n" + - "----------\n" + - "2. ERROR in X.java (at line 9)\n" + + "1. ERROR in X.java (at line 9)\n" + " new X().<N<?>>foo2(\"HI\", null);\n" + " ^^^^\n" + "Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N<?> is not a valid substitute for the bounded parameter <T extends N<T>>\n" + "----------\n" + - "3. ERROR in X.java (at line 10)\n" + + "2. ERROR in X.java (at line 10)\n" + " new X().<N<? extends N<?>>>foo2(\"HI\", null);\n" + " ^^^^\n" + "Bound mismatch: The generic method foo2(String, T) of type X is not applicable for the arguments (String, null). The inferred type N<? extends N<?>> is not a valid substitute for the bounded parameter <T extends N<T>>\n" + @@ -44882,7 +45179,7 @@ public void test1318() { } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation public void test1319() { - this.runNegativeTest( + this.runConformTest( new String[] { "X.java", // ================= "import java.util.List;\n" + @@ -44896,16 +45193,11 @@ public void test1319() { " }\n" + "}\n", // ================= }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().foo2(\"HI\", null, null, null);\n" + - " ^^^^\n" + - "Bound mismatch: The generic method foo2(String, U, T, W) of type X is not applicable for the arguments (String, null, null, null). The inferred type List<List<W>> is not a valid substitute for the bounded parameter <T extends List<U>>\n" + - "----------\n"); + ""); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation public void test1320() { - this.runNegativeTest( + this.runConformTest( new String[] { "X.java", // ================= "import java.util.List;\n" + @@ -44919,16 +45211,11 @@ public void test1320() { " }\n" + "}\n", // ================= }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().foo2(\"HI\", null, null, null);\n" + - " ^^^^\n" + - "Bound mismatch: The generic method foo2(String, U, T, W) of type X is not applicable for the arguments (String, null, null, null). The inferred type List<List<W>> is not a valid substitute for the bounded parameter <T extends List<U>>\n" + - "----------\n"); + ""); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation public void test1321() { - this.runNegativeTest( + this.runConformTest( new String[] { "X.java", // ================= "import java.util.List;\n" + @@ -44942,12 +45229,7 @@ public void test1321() { " }\n" + "}\n", // ================= }, - "----------\n" + - "1. ERROR in X.java (at line 8)\n" + - " new X().foo2(\"HI\", null, null, null);\n" + - " ^^^^\n" + - "Bound mismatch: The generic method foo2(String, U, T, W) of type X is not applicable for the arguments (String, null, null, null). The inferred type List<List<T>> is not a valid substitute for the bounded parameter <W extends List<U>>\n" + - "----------\n"); + ""); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 public void test1322() { @@ -45619,6 +45901,8 @@ public void test1340() { } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=235837 public void test1341() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE); this.runNegativeTest( new String[] { "X.java", // ================= @@ -45637,12 +45921,10 @@ public void test1341() { " foo((Collection<Number>) Arrays.asList(i, d));\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + "Cannot cast from List<Number&Comparable<?>> to Collection<Number>\n" + - "----------\n" + - "2. WARNING in X.java (at line 6)\n" + - " foo((Collection<Number>) Arrays.asList(i, d));\n" + - " ^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Number&Comparable<?> is created for a varargs parameter\n" + - "----------\n"); + "----------\n", + null, + true, + options); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation public void test1342() throws Exception { @@ -46895,7 +47177,7 @@ public void test1379() { } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=174447 public void test1380() { - this.runNegativeTest( + this.runConformTest( new String[] { "X.java", //----------------------------------------------------------------------- "public class X {\n" + @@ -46906,12 +47188,7 @@ public void test1380() { " }\n" + "}\n",//----------------------------------------------------------------------- }, - "----------\n" + - "1. ERROR in X.java (at line 5)\n" + - " f();\n" + - " ^\n" + - "Bound mismatch: The generic method f() of type X is not applicable for the arguments (). The inferred type Enum<Enum<E>> is not a valid substitute for the bounded parameter <E extends Enum<E>>\n" + - "----------\n"); + ""); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=247953 public void test1381() throws Exception { @@ -47920,8 +48197,8 @@ public void test1403() throws Exception { "Syntax error, insert \")\" to complete Expression\n" + "----------\n"); } -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242159 -public void _test1404() throws Exception { +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=242159 +public void test1404() throws Exception { this.runNegativeTest( new String[] { "X.java", @@ -47938,20 +48215,10 @@ public void _test1404() throws Exception { "}\n", }, "----------\n" + - "1. ERROR in X.java (at line 7)\n" + - " bar(); // 0 rejected\n" + - " ^^^\n" + - "Bound mismatch: The generic method bar() of type X<A> is not applicable for the arguments (). The inferred type Comparable<Comparable<B>> is not a valid substitute for the bounded parameter <B extends Comparable<B>>\n" + - "----------\n" + - "2. WARNING in X.java (at line 8)\n" + + "1. WARNING in X.java (at line 8)\n" + " X raw = bar(); // 1 accepted\n" + " ^\n" + "X is a raw type. References to generic type X<A> should be parameterized\n" + - "----------\n" + - "3. ERROR in X.java (at line 9)\n" + - " X<?> wild = bar(); // 2 rejected\n" + - " ^^^\n" + - "Bound mismatch: The generic method bar() of type X<A> is not applicable for the arguments (). The inferred type Comparable<Comparable<B>> is not a valid substitute for the bounded parameter <B extends Comparable<B>>\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=240807 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 34832ff92e..3c54f5f06c 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 @@ -4,7 +4,7 @@ * 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 * Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 282152 - [1.5][compiler] Generics code rejected by Eclipse but accepted by javac @@ -28,7 +28,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[] { "test322531j" }; +// TESTS_NAMES = new String[] { "test347426" }; // TESTS_NAMES = new String[] { "test1464" }; // TESTS_NUMBERS = new int[] { 1465 }; // TESTS_RANGE = new int[] { 1097, -1 }; @@ -1740,26 +1740,402 @@ public void test338011b() { compilerOptions15, null); } -//https://bugs.eclipse.org/bugs/show_bug.cgi?id=334493 +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=339478 +// To verify that diamond construct is not allowed in source level 1.6 or below +public void test339478a() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) + return; + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " X<String> x = new X<>();\n" + + " x.testFunction(\"SUCCESS\");\n" + + " }\n" + + " public void testFunction(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X<String> x = new X<>();\n" + + " ^\n" + + "\'<>\' operator is not allowed for source level below 1.7\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=339478 +// To verify that diamond construct is not allowed in source level 1.6 or below +public void test339478b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " X<> x1 = null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X<> x1 = null;\n" + + " ^\n" + + "Incorrect number of arguments for type X<T>; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478c() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "public class X implements Map<> {\n" + + " static Map<> foo (Map<> x) { \n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X implements Map<> {\n" + + " ^^^\n" + + "Incorrect number of arguments for type Map<K,V>; it cannot be parameterized with arguments <>\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " static Map<> foo (Map<> x) { \n" + + " ^^^\n" + + "Incorrect number of arguments for type Map<K,V>; it cannot be parameterized with arguments <>\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " static Map<> foo (Map<> x) { \n" + + " ^^^\n" + + "Incorrect number of arguments for type Map<K,V>; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478d() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "public class X {\n" + + " static Map<> foo () { \n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " static Map<> foo () { \n" + + " ^^^\n" + + "Incorrect number of arguments for type Map<K,V>; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478e() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class Y<K> {\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " X<String>.Y<> [] y = null; \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X<String>.Y<> [] y = null; \n" + + " ^^^^^^^^^^^\n" + + "Incorrect number of arguments for type X<String>.Y; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478f() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class Y<K> {\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " X<String>.Y<> y = null; \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X<String>.Y<> y = null; \n" + + " ^^^^^^^^^^^\n" + + "Incorrect number of arguments for type X<String>.Y; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478g() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public void foo(Object x) {\n" + + " if (x instanceof X<>) { \n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (x instanceof X<>) { \n" + + " ^\n" + + "Incorrect number of arguments for type X<T>; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478h() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public void foo(Object x) throws X.Y<>.LException {\n" + + " }\n" + + " static class Y<T> {\n" + + " static class LException extends Throwable {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(Object x) throws X.Y<>.LException {\n" + + " ^^^\n" + + "Incorrect number of arguments for type X.Y; it cannot be parameterized with arguments <>\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " static class LException extends Throwable {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class LException does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +public void test339478i() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public void foo () {\n" + + " Object o = new X<> [10];\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = new X<> [10];\n" + + " ^\n" + + "Incorrect number of arguments for type X<T>; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478j() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " X<>[] x1 = null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X<>[] x1 = null;\n" + + " ^\n" + + "Incorrect number of arguments for type X<T>; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478k() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X<>[] x1 = null;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X<>[] x1 = null;\n" + + " ^\n" + + "Incorrect number of arguments for type X<T>; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478l() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " X<> x1 = null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X<> x1 = null;\n" + + " ^\n" + + "Incorrect number of arguments for type X<T>; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478m() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X<> f1 = null;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X<> f1 = null;\n" + + " ^\n" + + "Incorrect number of arguments for type X<T>; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478n() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public void foo(X<> args) {\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(X<> args) {\n" + + " ^\n" + + "Incorrect number of arguments for type X<T>; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478o() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " new X<>(){\n" + + " void newMethod(){\n" + + " }\n" + + " }.testFunction(\"SUCCESS\");\n" + + " }\n" + + " public void testFunction(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + "}", + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X<>(){\n" + + " ^\n" + + "\'<>\' operator is not allowed for source level below 1.7\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " new X<>(){\n" + + " ^\n" + + "\'<>\' cannot be used with anonymous classes\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X<>(){\n" + + " ^\n" + + "\'<>\' cannot be used with anonymous classes\n" + + "----------\n"); +} +public void test339478p() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " X Test = new X<>(){\n" + + " void newMethod(){\n" + + " }\n" + + " }.testFunction(\"SUCCESS\");\n" + + " }\n" + + " public void testFunction(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + "}", + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " X Test = new X<>(){\n" + + " ^\n" + + "X is a raw type. References to generic type X<T> should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " X Test = new X<>(){\n" + + " ^\n" + + "\'<>\' operator is not allowed for source level below 1.7\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " X Test = new X<>(){\n" + + " ^\n" + + "\'<>\' cannot be used with anonymous classes\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " X Test = new X<>(){\n" + + " ^\n" + + "X is a raw type. References to generic type X<T> should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " X Test = new X<>(){\n" + + " ^\n" + + "\'<>\' cannot be used with anonymous classes\n" + + "----------\n"); +} +public void test339478q() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X Test = new X<>();\n" + + " }\n" + + "}", + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X Test = new X<>();\n" + + " ^\n" + + "\'<>\' operator is not allowed for source level below 1.7\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " X Test = new X<>();\n" + + " ^\n" + + "The type X is not generic; it cannot be parameterized with arguments <>\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X Test = new X<>();\n" + + " ^\n" + + "The type X is not generic; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334493 public void test334493() { - this.runNegativeTest( - new String[] { - "X.java", - "interface Super<P> {}\n" + - "class Y<C> implements Super<Integer>{}\n" + - "interface II extends Super<Double>{}\n" + - "class S<A> extends Y<Byte> {}\n" + - "interface T<B> extends II{}\n" + - "public class X {\n" + - " public static void main(String argv[]) {\n" + - " S<Integer> s = null;\n" + - " T<Integer> t = null;\n" + - " t = (T) s; //casting to raw type, no error\n" + - " System.out.println(t);\n" + - " }\n" + - "}\n" - }, - this.complianceLevel < ClassFileConstants.JDK1_7 ? + this.runNegativeTest( + new String[] { + "X.java", + "interface Super<P> {}\n" + + "class Y<C> implements Super<Integer>{}\n" + + "interface II extends Super<Double>{}\n" + + "class S<A> extends Y<Byte> {}\n" + + "interface T<B> extends II{}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " S<Integer> s = null;\n" + + " T<Integer> t = null;\n" + + " t = (T) s; //casting to raw type, no error\n" + + " System.out.println(t);\n" + + " }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. ERROR in X.java (at line 10)\n" + " t = (T) s; //casting to raw type, no error\n" + @@ -1771,7 +2147,7 @@ public void test334493() { " ^^^^^\n" + "Type safety: The expression of type T needs unchecked conversion to conform to T<Integer>\n" + "----------\n" : - "----------\n" + + "----------\n" + "1. WARNING in X.java (at line 10)\n" + " t = (T) s; //casting to raw type, no error\n" + " ^^^^^\n" + @@ -1783,4 +2159,310 @@ public void test334493() { "T is a raw type. References to generic type T<B> should be parameterized\n" + "----------\n"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334313 +public void test334313() { + this.runNegativeTest( + new String[] { + "X.java", + "abstract class C<T> {\n" + + " public abstract Object foo(T x);\n" + + " public Integer foo(String x){ return 1; }\n" + + "}\n" + + "public class X extends C<String> {\n" + + " zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " zork z;\n" + + " ^^^^\n" + + "zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334313 +public void test334313b() { + this.runNegativeTest( + new String[] { + "X.java", + "abstract class C<T> {\n" + + " public abstract Integer foo(T x);\n" + + " public Object foo(String x){ return 1; }\n" + + "}\n" + + "public class X extends C<String> {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public class X extends C<String> {\n" + + " ^\n" + + "The type X must implement the inherited abstract method C<String>.foo(String) to override C<String>.foo(String)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334313 +public void test334313c() { + this.runNegativeTest( + new String[] { + "X.java", + "abstract class B<T> {\n" + + " public abstract Object foo(T x);\n" + + "}\n" + + "abstract class C<T> extends B<T> {\n" + + " public Integer foo(String x){ return 1; }\n" + + "}\n" + + "public class X extends C<String> {\n" + + " zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " zork z;\n" + + " ^^^^\n" + + "zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334313 +public void test334313d() { + this.runNegativeTest( + new String[] { + "X.java", + "abstract class B<T> {\n" + + " public abstract Integer foo(T x);\n" + + "}\n" + + "abstract class C<T> extends B<T> {\n" + + " public Object foo(String x){ return 1; }\n" + + "}\n" + + "public class X extends C<String> {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public class X extends C<String> {\n" + + " ^\n" + + "The type X must implement the inherited abstract method B<String>.foo(String) to override C<String>.foo(String)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334313 +public void test334313e() { + this.runNegativeTest( + new String[] { + "X.java", + "abstract class C<T> {\n" + + " public abstract Object foo(T x);\n" + + " public static Integer foo(String x){ return 1; }\n" + + "}\n" + + "public class X extends C<String> {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public class X extends C<String> {\n" + + " ^\n" + + "The static method foo(String) conflicts with the abstract method in C<String>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=347145 +public void test347145() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {}\n" + + "class B<V> extends A {} \n" + + "class F<T extends A, Y extends B<T>> {\n" + + " static <U extends A , V extends B<U>> F<U,V> g() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " F<? extends B, ? extends B<? extends B>> f011 = F.g();\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " F<? extends B, ? extends B<? extends B>> f011 = F.g();\n" + + " ^\n" + + "B is a raw type. References to generic type B<V> should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " F<? extends B, ? extends B<? extends B>> f011 = F.g();\n" + + " ^\n" + + "B is a raw type. References to generic type B<V> should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=347426 +public void test347426() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class A<T extends B<?>> { }\n" + + " class B<T extends A<?>> {\n" + + " D<? extends B<T>> x;\n" + + " }\n" + + " class D<T extends B<?>> {}\n" + + " <E extends B<?>> X(E x, D<B<A<?>>> d) {\n" + + " if (x.x == d) {\n" + + " return;\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=347426 +public void test347426b() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class A<T extends X<?>> {\n" + + " B<? extends A<T>> x;\n" + + " }\n" + + " class B<T extends A<?>> {}\n" + + " boolean b = ((A<?>)null).x == ((B<A<X<?>>>)null); \n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=347426 +public void test347426c() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class A<T extends X<? extends String>> {\n" + + " B<? extends A<T>> x;\n" + + " }\n" + + " class B<T extends A<?>> {}\n" + + " boolean b = ((A<? extends X<?>>)null).x == ((B<A<X<? extends String>>>)null); \n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=283353 +public void test283353() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " EntityKey entityKey = null;\n" + + " new EntityCondenser().condense(entityKey); \n" + + " }\n" + + " public static class EntityCondenser {\n" + + " <I, E extends EntityType<I, E, K>, K extends EntityKey<I>> void condense(K entityKey) {\n" + + " }\n" + + " }\n" + + " public class EntityKey<I> {}\n" + + " public interface EntityType<\n" + + " I,\n" + + " E extends EntityType<I, E, K>,\n" + + " K extends EntityKey<I>> {\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=347600 +public void test347600() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {}\n" + + "class B<V> extends A {} \n" + + "class D extends B<E> {}\n" + + "class E extends B<D> {}\n" + + "public class X<T, Y extends B<U>, U extends B<Y>> { \n" + + " public static <T1, Y1 extends B<U1>, U1 extends B<Y1>> X<T1, Y1, U1> getX() {\n" + + " return null;\n" + + " }\n" + + " X<B, ? extends D, ? extends E> f = getX(); \n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " X<B, ? extends D, ? extends E> f = getX(); \n" + + " ^\n" + + "B is a raw type. References to generic type B<V> should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=347746 +public void test347746() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class A<T extends B<?>> {}\n" + + " class B<T extends A<?>> extends D {}\n" + + " class C<T extends D> {}\n" + + " class D {}\n" + + " class E<T extends C<? extends B<?>>> {}\n" + + " <U extends C<V>, V extends B<W>, W extends A<V>> W foo(E<U> e) {\n" + + " return goo(e);\n" + + " }\n" + + " <P extends C<Q>, Q extends B<R>, R extends A<Q>> R goo(E<P> e) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348493 +// To verify that diamond construct is not allowed in source level 1.6 or below +public void test348493() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) + return; + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class X2<Z> {}\n" + + " public static void main(String[] args) {\n" + + " X<String>.X2<> x = new X<String>().new X2<>();\n" + + " }\n" + + " public void testFunction(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X<String>.X2<> x = new X<String>().new X2<>();\n" + + " ^^^^^^^^^^^^\n" + + "Incorrect number of arguments for type X<String>.X2; it cannot be parameterized with arguments <>\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " X<String>.X2<> x = new X<String>().new X2<>();\n" + + " ^^\n" + + "\'<>\' operator is not allowed for source level below 1.7\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348493 +// To verify that diamond construct is not allowed in source level 1.6 or below +public void test348493a() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) + return; + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " X<> x = new X<>();\n" + + " }\n" + + " public void testFunction(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X<> x = new X<>();\n" + + " ^\n" + + "Incorrect number of arguments for type X<T>; it cannot be parameterized with arguments <>\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " X<> x = new X<>();\n" + + " ^\n" + + "\'<>\' operator is not allowed for source level below 1.7\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/GenericsRegressionTest_1_7.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java new file mode 100644 index 0000000000..4fddfd872f --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java @@ -0,0 +1,2308 @@ +/******************************************************************************* + * Copyright (c) 2011 IBM Corporation. + * 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 + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; +public class GenericsRegressionTest_1_7 extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "test0056c" }; +// TESTS_NUMBERS = new int[] { 40, 41, 43, 45, 63, 64 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public GenericsRegressionTest_1_7(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_7); +} +public void test001() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " X<String> x = new X<>();\n" + + " x.testFunction(\"SUCCESS\");\n" + + " }\n" + + " public void testFunction(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +public void test001a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " X<String> x = new X<>();\n" + + " x.testFunction(1);\n" + + " }\n" + + " public void testFunction(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " x.testFunction(1);\n" + + " ^^^^^^^^^^^^\n" + + "The method testFunction(String) in the type X<String> is not applicable for the arguments (int)\n" + + "----------\n"); +} +public void test001b() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " java.util.ArrayList<String> x = new java.util.ArrayList<>();\n" + + " x.add(\"\");\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +// fields +public void test001b_1() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " static java.util.ArrayList<String> x = new java.util.ArrayList<>();\n" + + " public static void main(String[] args) {\n" + + " X.x.add(\"\");\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +public void test001c() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " java.util.ArrayList<String> x = new java.util.ArrayList<>();\n" + + " x.add(1);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " x.add(1);\n" + + " ^^^\n" + + "The method add(int, String) in the type ArrayList<String> is not applicable for the arguments (int)\n" + + "----------\n"); +} +// fields +public void test001c_1() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " static java.util.ArrayList<String> x = new java.util.ArrayList<>();\n" + + " public static void main(String[] args) {\n" + + " X.x.add(1);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X.x.add(1);\n" + + " ^^^\n" + + "The method add(int, String) in the type ArrayList<String> is not applicable for the arguments (int)\n" + + "----------\n"); +} +public void test001d() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X<T> {" + + " public void ab(ArrayList<String> al){\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String> x = new X<>();\n" + + " x.ab(new ArrayList<>());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " x.ab(new ArrayList<>());\n" + + " ^^\n" + + "The method ab(ArrayList<String>) in the type X<String> is not applicable for the arguments (ArrayList<Object>)\n" + + "----------\n"); +} +public void test001e() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X<T> {" + + " public void ab(ArrayList<T> al){\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String> x = new X<>();\n" + + " x.ab(new ArrayList<>());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " x.ab(new ArrayList<>());\n" + + " ^^\n" + + "The method ab(ArrayList<String>) in the type X<String> is not applicable for the arguments (ArrayList<Object>)\n" + + "----------\n"); +} +public void test001f() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class X2<T>{\n" + + " void methodx(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String>.X2<String> x = new X<>().new X2<>();\n" + + " x.methodx(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " class X2<T>{\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " X<String>.X2<String> x = new X<>().new X2<>();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Object>.X2<String> to X<String>.X2<String>\n" + + "----------\n"); +} +// fields +public void test001f_1() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class X2<T>{\n" + + " void methodx(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " }\n" + + " X<String>.X2<String> x;\n" + + " public static void main(String[] args) {\n" + + " X test = new X();\n" + + " test.x = new X<>().new X2<>();\n" + + " test.x.methodx(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +public void test001g() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class X2<K>{\n" + + " void methodx(T param, K param2){\n" + + " System.out.println(param);\n" + + " System.out.println(param2);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String>.X2<Integer> x = new X<>().new X2<>();\n" + + " x.methodx(\"SUCCESS\",1);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " X<String>.X2<Integer> x = new X<>().new X2<>();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Object>.X2<Integer> to X<String>.X2<Integer>\n" + + "----------\n"); +} +public void test001g_1() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class X2<K>{\n" + + " void methodx(T param, K param2){\n" + + " System.out.println(param);\n" + + " System.out.println(param2);\n" + + " }\n" + + " }\n" + + " X<String>.X2<Integer> x;\n" + + " public static void main(String[] args) {\n" + + " X test = new X();" + + " test.x = new X<>().new X2<>();\n" + + " test.x.methodx(\"SUCCESS\",1);\n" + + " }\n" + + "}", + }, + "SUCCESS\n1"); +} +public void test001h() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class X2<T>{\n" + + " void methodx(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String>.X2<String> x = new X<>().new X2<>();\n" + + " x.methodx(1);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " class X2<T>{\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " X<String>.X2<String> x = new X<>().new X2<>();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Object>.X2<String> to X<String>.X2<String>\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " x.methodx(1);\n" + + " ^^^^^^^\n" + + "The method methodx(String) in the type X<String>.X2<String> is not applicable for the arguments (int)\n" + + "----------\n"); +} +public void test001h_1() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class X2<T>{\n" + + " void methodx(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " }\n" + + " X<String>.X2<String> x;\n" + + " public static void main(String[] args) {\n" + + " X test = new X();\n" + + " test.x = new X<>().new X2<>();\n" + + " test.x.methodx(1);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " class X2<T>{\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " X test = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X<T> should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " X test = new X();\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 10)\n" + + " test.x = new X<>().new X2<>();\n" + + " ^\n" + + "Type safety: The field x from the raw type X is assigned a value of type X<Object>.X2<Object>. References to generic type X<T> should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 11)\n" + + " test.x.methodx(1);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method methodx(Object) belongs to the raw type X.X2. References to generic type X<T>.X2<T> should be parameterized\n" + + "----------\n"); +} +public void test001h_2() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class X2<T>{\n" + + " void methodx(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " }\n" + + " X<String>.X2<String> x;\n" + + " public static void main(String[] args) {\n" + + " X test = new X();\n" + + " test.x = new X<>().new X2<>();\n" + + " test.x.methodx(1);\n" + + " }\n" + + "}", + }, + "1"); +} +public void test001i() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class X2<K>{\n" + + " class X22<I>{\n" + + " void methodx(T param, K param2, I param3){\n" + + " System.out.println(param);\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String> test = new X<>();" + + " X<String>.X2<Integer>.X22<X<String>> x = new X<>().new X2<>().new X22<>();\n" + + " x.methodx(\"SUCCESS\", 1, test);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " X<String> test = new X<>(); X<String>.X2<Integer>.X22<X<String>> x = new X<>().new X2<>().new X22<>();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Object>.X2<Object>.X22<X<String>> to X<String>.X2<Integer>.X22<X<String>>\n" + + "----------\n"); +} +public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " X x = new X<>();\n" + + " x.testFunction(\"SUCCESS\");\n" + + " }\n" + + " public void testFunction(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " X x = new X<>();\n" + + " ^\n" + + "X is a raw type. References to generic type X<T> should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " x.testFunction(\"SUCCESS\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method testFunction(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + + "----------\n"); +} +public void test003() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public static void main(String[] args) {\n" + + " new X<>().testFunction(\"SUCCESS\");\n" + + " }\n" + + " public void testFunction(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} + +public void test004b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class X2<U> {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X<>().new X2<>(){\n" + + " void newMethod(){\n" + + " }\n" + + " };\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " new X<>().new X2<>(){\n" + + " ^^\n" + + "\'<>\' cannot be used with anonymous classes\n" + + "----------\n"); +} +public void test004c() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class X2<U> {\n" + + " U f1;" + + " public void setF(U a){\n" + + " this.f1 = a;" + + " System.out.println(this.f1);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X<>().new X2<Integer>(){\n" + + " void newMethod(){\n" + + " }\n" + + " }.setF(1);\n" + + " }\n" + + "}", + }, + "1"); +} + +public void test006() { + this.runConformTest( + new String[] { + "X.java", + "class X1<T> {\n" + + " int abc = 1;\n" + + " public void testFunction(T param){\n" + + " System.out.println(param + \"X1\");\n" + + " }\n" + + "}\n" + + "public class X<T> extends X1<T> {\n" + + " public static void main(String[] args) {\n" + + " X1<String> x = new X<>();\n" + + " x.testFunction(\"SUCCESS\");\n" + + " }\n" + + " public void testFunction(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +// shows the difference between using <> and the raw type - different semantics +public void test007() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " T field1;" + + " public X(T param){\n" + + " field1 = param;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.testFunction(new X<>(\"hello\").getField());\n" + // prints 1 + " X.testFunction(new X(\"hello\").getField());\n" + //prints 2 + " }\n" + + " public static void testFunction(String param){\n" + + " System.out.println(1);\n" + + " }\n" + + " public static void testFunction(Object param){\n" + + " System.out.println(2);\n" + + " }\n" + + " public T getField(){\n" + + " return field1;" + + " }\n" + + "}", + }, + "1\n" + + "2"); +} +public void test007a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " public X(){\n" + + " }\n" + + " public X(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " public static void testFunction(X<String> param){\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.testFunction(new X<>());\n" + + " X.testFunction(new X(\"hello\"));\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X.testFunction(new X<>());\n" + + " ^^^^^^^^^^^^\n" + + "The method testFunction(X<String>) in the type X is not applicable for the arguments (X<Object>)\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " X.testFunction(new X(\"hello\"));\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The constructor X(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " X.testFunction(new X(\"hello\"));\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X needs unchecked conversion to conform to X<String>\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " X.testFunction(new X(\"hello\"));\n" + + " ^\n" + + "X is a raw type. References to generic type X<T> should be parameterized\n" + + "----------\n"); +} +//shows the difference between using <> and the raw type - different semantics +public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " T field1;\n" + + " public X(T param){\n" + + " field1 = param;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<?> x1 = new X(1).get(\"\");\n" + // ok - passing String where Object is expected + " X<?> x2 = new X<>(1).get(\"\");\n" + // bad - passing String where Integer is expected + " }\n" + + " public X<T> get(T t){\n" + + " return this;" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X<?> x1 = new X(1).get(\"\");\n" + + " ^^^^^^^^\n" + + "Type safety: The constructor X(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X<?> x1 = new X(1).get(\"\");\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The method get(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " X<?> x1 = new X(1).get(\"\");\n" + + " ^\n" + + "X is a raw type. References to generic type X<T> should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " X<?> x2 = new X<>(1).get(\"\");\n" + + " ^^^\n" + + "The method get(Integer) in the type X<Integer> is not applicable for the arguments (String)\n" + + "----------\n"); +} + +public void test0014() { + this.runConformTest( + new String[] { + "X.java", + "public class X<J,K> {\n" + + " public static void main(String[] args) {\n" + + " X<String,Integer> x = new X<>();\n" + + " x.testFunction(\"SUCCESS\", 123);\n" + + " }\n" + + " public void testFunction(J param, K param2){\n" + + " System.out.println(param);\n" + + " System.out.println(param2);\n" + + " }\n" + + "}", + }, + "SUCCESS\n" + + "123"); +} +public void test0014a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<J,K> {\n" + + " public static void main(String[] args) {\n" + + " X<String,Integer> x = new X<>();\n" + + " x.testFunction(123, \"SUCCESS\");\n" + + " }\n" + + " public void testFunction(J param, K param2){\n" + + " System.out.println(param);\n" + + " System.out.println(param2);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " x.testFunction(123, \"SUCCESS\");\n" + + " ^^^^^^^^^^^^\n" + + "The method testFunction(String, Integer) in the type X<String,Integer> is not applicable for the arguments (int, String)\n" + + "----------\n"); +} +public void test0015() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X(){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " X (T t) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String> x = new X<>();\n" + + " X<String> x2 = new X<>(\"\");\n" + + " }\n" + + "}", + }, + "const.1\nconst.2"); +} +// To verify that <> cannot be used with explicit type arguments to generic constructor. +public void test0016() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " <E> X(){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " <K,J> X (Integer i) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String> x = new <String>X<>();\n" + + " X<String> x2 = new <String, Integer>X<>(1);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " X<String> x = new <String>X<>();\n" + + " ^^^^^^\n" + + "Explicit type arguments cannot be used with \'<>\' in an allocation expression\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " X<String> x2 = new <String, Integer>X<>(1);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Explicit type arguments cannot be used with \'<>\' in an allocation expression\n" + + "----------\n"); +} +public void test0016a() { + this.runConformTest( // javac fails to compile this, looks buggy + new String[] { + "X.java", + "public class X<T> {\n" + + " <E> X(){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " <K,J> X (Integer i) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String> x = new X<>();\n" + + " X<String> x2 = new X<>(1);\n" + + " }\n" + + "}", + }, + "const.1\nconst.2"); +} +// To verify that <> cannot be used with explicit type arguments to a generic constructor. +public void test0016b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X<String> x;\n" + + " X<String> x2;\n" + + " <E> X(){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " <K,J> X (Integer i) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<Integer> test = new <String>X<>();\n" + + " test.x = new <String>X<>();\n" + + " test.x2 = new <String, Integer>X<>(1);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X<Integer> test = new <String>X<>();\n" + + " ^^^^^^\n" + + "Explicit type arguments cannot be used with \'<>\' in an allocation expression\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " test.x = new <String>X<>();\n" + + " ^^^^^^\n" + + "Explicit type arguments cannot be used with \'<>\' in an allocation expression\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " test.x2 = new <String, Integer>X<>(1);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Explicit type arguments cannot be used with \'<>\' in an allocation expression\n" + + "----------\n"); +} +//To verify that a parameterized invocation of a generic constructor works even if <> is used +//to elide class type parameters. This test handles fields +public void test0016c() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X<String> x;\n" + + " X<String> x2;\n" + + " <E> X(){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " <K,J> X (Integer i) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<Integer> test = new X<>();\n" + + " test.x = new X<>();\n" + + " test.x2 = new X<>(1);\n" + + " }\n" + + "}", + }, + "const.1\nconst.1\nconst.2"); +} +// To verify that <> cannot be used with explicit type arguments to generic constructor. +public void test0017() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X(int i){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " <K,J> X (Integer i) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String> x = new X<>(1);\n" + + " X<String> x2 = new <String, Integer>X<>(1);\n" + + " Integer i = 1;\n" + + " X<String> x3 = new <String, Integer>X<>(i);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " X<String> x2 = new <String, Integer>X<>(1);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Explicit type arguments cannot be used with \'<>\' in an allocation expression\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " X<String> x3 = new <String, Integer>X<>(i);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Explicit type arguments cannot be used with \'<>\' in an allocation expression\n" + + "----------\n" +); +} +// To verify that a parameterized invocation of a non-generic constructor works even if <> is used +// to elide class type parameters. +public void test0017a() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X(int i){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " <K,J> X (Integer i) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String> x = new X<>(1);\n" + + " X<String> x2 = new X<>(1);\n" + + " Integer i = 1;\n" + + " X<String> x3 = new X<>(i);\n" + + " }\n" + + "}", + }, + "const.1\nconst.1\nconst.2"); +} +// To verify that the correct constructor is found by parameter substitution in the diamond case +public void test0018() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X(T t){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " X (T t, Integer i) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X<>(\"\");\n" + + " X x2 = new X<>(\"\",1);\n" + + " }\n" + + "}", + }, + "const.1\nconst.2"); +} +// To verify that the correct constructor is found by parameter substitution +// in the diamond case -- fields +public void test0018b() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X f1;\n" + + " X f2;\n" + + " X(T t){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " X (T t, Integer i) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X<>(\"\");\n" + + " x.f1 = new X<>(\"\");\n" + + " x.f2 = new X<>(\"\",1);\n" + + " }\n" + + "}", + }, + "const.1\nconst.1\nconst.2"); +} +public void test0019() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String s = new String<>(\"junk\");\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " String s = new String<>(\"junk\");\n" + + " ^^^^^^\n" + + "The type String is not generic; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +// check inference at method argument position. +public void test0020() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " Zork z;\n" + + " public X(T t) {}\n" + + " int f(X<String> p) {return 0;}\n" + + " int x = f(new X<>(\"\"));\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//check inference at method argument position. +public void test0021() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "class X<T> {\n" + + " public X(T t) {}\n" + + " int f(List<String> p) {return 0;}\n" + + " int x = f(new ArrayList<>());\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " int x = f(new ArrayList<>());\n" + + " ^\n" + + "The method f(List<String>) in the type X<T> is not applicable for the arguments (ArrayList<Object>)\n" + + "----------\n"); +} +public void test0022() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "class StringKeyHashMap<V> extends HashMap<String, V> { \n" + + "}\n" + + "\n" + + "class IntegerValueHashMap<K> extends HashMap<K, Integer> { \n" + + "}\n" + + "\n" + + "public class X {\n" + + " Map<String, Integer> m1 = new StringKeyHashMap<>();\n" + + " Map<String, Integer> m2 = new IntegerValueHashMap<>();\n" + + "}\n" + }, + ""); +} +public void test0023() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "class StringKeyHashMap<V> extends HashMap<String, V> { \n" + + "}\n" + + "\n" + + "class IntegerValueHashMap<K> extends HashMap<K, Integer> { \n" + + "}\n" + + "\n" + + "public class X {\n" + + " Map<String, Integer> m1 = new StringKeyHashMap<>(10);\n" + + " Map<String, Integer> m2 = new IntegerValueHashMap<>();\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " class StringKeyHashMap<V> extends HashMap<String, V> { \n" + + " ^^^^^^^^^^^^^^^^\n" + + "The serializable class StringKeyHashMap does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " class IntegerValueHashMap<K> extends HashMap<K, Integer> { \n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The serializable class IntegerValueHashMap does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " Map<String, Integer> m1 = new StringKeyHashMap<>(10);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for StringKeyHashMap<>\n" + + "----------\n"); +} +// check inference at return expression. +public void test0024() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "class X<T> {\n" + + " public X() {}\n" + + " X<String> f(List<String> p) {return new X<>();}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " import java.util.ArrayList;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The import java.util.ArrayList is never used\n" + + "----------\n"); +} +// check inference at cast expression. +public void test0025() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "class X<T> {\n" + + " public X() {}\n" + + " void f(List<String> p) { Object o = (X<String>) new X<>();}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " void f(List<String> p) { Object o = (X<String>) new X<>();}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X<Object> to X<String>\n" + + "----------\n"); +} +// Test various scenarios. +public void test0026() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "public class X<T> {\n" + + " X(T t) {}\n" + + " X(String s) {}\n" + + " X(List<?> l) {}\n" + + " X<T> idem() { return this; }\n" + + " X<Number> x = new X<>(1);\n" + + " X<Integer> x2 = new X<>(1);\n" + + " List<?> list = new ArrayList<>();\n" + + " X<?> x3 = new X<>(1);\n" + + " X<Object> x4 = new X<>(1).idem();\n" + + " X<Object> x5 = new X<>(1);\n" + + " int m(X<String> xs) { return 0; }\n" + + " int i = m(new X<>(\"\"));\n" + + " X<?> x6 = new X<>(list);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " X<Number> x = new X<>(1);\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Integer> to X<Number>\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " X<Object> x4 = new X<>(1).idem();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Integer> to X<Object>\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " X<Object> x5 = new X<>(1);\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Integer> to X<Object>\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " int i = m(new X<>(\"\"));\n" + + " ^\n" + + "The method m(X<String>) in the type X<T> is not applicable for the arguments (X<Object>)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=344655 +public void test0027() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class Y<U> {\n" + + " <K,J> Y (Integer i) {\n" + + " }\n" + + " }\n" + + "\n" + + " <K,J> X (Integer i) {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X<String> x = new <String, Integer> X<>(1);\n" + + " X<String> x2 = x.new <String, Integer> Y<>(1);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X<String> x = new <String, Integer> X<>(1);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Explicit type arguments cannot be used with \'<>\' in an allocation expression\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " X<String> x2 = x.new <String, Integer> Y<>(1);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Explicit type arguments cannot be used with \'<>\' in an allocation expression\n" + + "----------\n" +); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345239 +public void test0028() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X<String> x = new X<> () {}\n;" + + " class Y<U> {\n" + + " }\n" + + " X<String>.Y<String> y = x.new Y<>() {};\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X<String> x = new X<> () {}\n" + + " ^\n" + + "\'<>\' cannot be used with anonymous classes\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " X<String>.Y<String> y = x.new Y<>() {};\n" + + " ^\n" + + "\'<>\' cannot be used with anonymous classes\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345359 +public void test0029() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X(T t) {}\n" + + " X<String> f2 = new X<>(new Y()); \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X<String> f2 = new X<>(new Y()); \n" + + " ^\n" + + "Y cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345359 +public void test0029a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class I<T> {\n" + + " I(T t) {}\n" + + " }\n" + + " X.I<String> f = new X().new I<>(new Y()); \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X.I<String> f = new X().new I<>(new Y()); \n" + + " ^\n" + + "Y cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026 +public void test0030() { + this.runNegativeTest( + new String[] { + "X.java", + "class C {}\n" + + "interface I {}\n" + + "public class X<T extends C & I> {\n" + + " X() {}\n" + + " X f = new X<>();\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " X f = new X<>();\n" + + " ^\n" + + "X is a raw type. References to generic type X<T> should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026 +public void test0031() { + this.runConformTest( + new String[] { + "X.java", + "class C {}\n" + + "interface I {}\n" + + "public class X<T extends C & I> {\n" + + " X() {}\n" + + " X<?> f = new X<>();\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026 +public void test0032() { + this.runConformTest( + new String[] { + "X.java", + "class C {}\n" + + "interface I {}\n" + + "public class X<T extends C & I> {\n" + + " static <U extends C & I> X<U> getX() {\n" + + " return null;\n" + + " }\n" + + " X<?> f2 = getX();\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346026 +public void test0033() { + this.runNegativeTest( + new String[] { + "X.java", + "class C {}\n" + + "interface I {}\n" + + "public class X<T extends C & I> {\n" + + " static <U extends C & I> X<U> getX() {\n" + + " return null;\n" + + " }\n" + + " X f2 = getX();\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X f2 = getX();\n" + + " ^\n" + + "X is a raw type. References to generic type X<T> should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0034() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X(T t) {}\n" + + " X() {}\n" + + " void foo(T a) {\n" + + " System.out.println(a);\n" + + " }\n" + + " class Y<K>{\n" + + " Y(T t,K k) {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<Integer> x1 = new X<>(1,1);\n" + + " X<Integer> x2 = new X<>(1);\n" + + " X<Integer> x3 = new X<>();\n" + + " X<Integer>.Y<String> y1 = new X<>(1,1).new Y<>();\n" + + " X<Integer>.Y<String> y2 = new X<>(1,1).new Y<>(1);\n" + + " X<Integer>.Y<String> y3 = new X<>(1).new Y<>(1);\n" + + " X<Integer>.Y<String> y4 = new X<>(1).new Y<>(\"\",\"\");\n" + + " X<Integer>.Y<String> y5 = new X<>(1).new Y<>(1,\"\");\n" + + " X<Integer>.Y<String> y6 = new X<>().new Y<>(1,\"\");\n" + + " X<Integer>.Y<String> y7 = new X<>().new Y<>(1,1);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X<Integer> x1 = new X<>(1,1);\n" + + " ^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " X<Integer>.Y<String> y1 = new X<>(1,1).new Y<>();\n" + + " ^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " X<Integer>.Y<String> y2 = new X<>(1,1).new Y<>(1);\n" + + " ^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n" + + "4. ERROR in X.java (at line 16)\n" + + " X<Integer>.Y<String> y3 = new X<>(1).new Y<>(1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for Y<>\n" + + "----------\n" + + "5. ERROR in X.java (at line 17)\n" + + " X<Integer>.Y<String> y4 = new X<>(1).new Y<>(\"\",\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for Y<>\n" + + "----------\n" + + "6. ERROR in X.java (at line 19)\n" + + " X<Integer>.Y<String> y6 = new X<>().new Y<>(1,\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Object>.Y<String> to X<Integer>.Y<String>\n" + + "----------\n" + + "7. ERROR in X.java (at line 20)\n" + + " X<Integer>.Y<String> y7 = new X<>().new Y<>(1,1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Object>.Y<Integer> to X<Integer>.Y<String>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0035() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X(T t) {}\n" + + " X() {}\n" + + " @SafeVarargs\n" + + " X(String abc, String abc2, T... t) {}\n" + + " void foo(T a) {\n" + + " System.out.println(a);\n" + + " }\n" + + " class Y<K>{\n" + + " @SafeVarargs\n" + + " Y(T t,String abc, K... k) {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<Integer> x1 = new X<>(1,1);\n" + + " X<Integer> x2 = new X<>(1);\n" + + " X<Integer> x3 = new X<>();\n" + + " X<Integer> x4 = new X<>(\"\",\"\");\n" + + " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + + " X<Integer> x6 = new X<>(\"\",\"\",1);\n" + + " X<Integer>.Y<String> y1 = new X<>(1,1).new Y<>();\n" + + " X<Integer>.Y<String> y2 = new X<>(\"\",1).new Y<>(\"\");\n" + + " X<Integer>.Y<String> y3 = new X<>(1).new Y<>(1);\n" + + " X<Integer>.Y<String> y4 = new X<>(1).new Y<>(1,\"\");\n" + + " X<Integer>.Y<String> y5 = new X<>(1).new Y<>(1,\"\",\"\");\n" + + " X<Integer>.Y<String> y6 = new X<>().new Y<>(1,\"\",1);\n" + + " X<Integer>.Y<String> y7 = new X<>().new Y<>(\"\",\"\",1);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " X<Integer> x1 = new X<>(1,1);\n" + + " ^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<String> to X<Integer>\n" + + "----------\n" + + "3. ERROR in X.java (at line 20)\n" + + " X<Integer>.Y<String> y1 = new X<>(1,1).new Y<>();\n" + + " ^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n" + + "4. ERROR in X.java (at line 21)\n" + + " X<Integer>.Y<String> y2 = new X<>(\"\",1).new Y<>(\"\");\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n" + + "5. ERROR in X.java (at line 22)\n" + + " X<Integer>.Y<String> y3 = new X<>(1).new Y<>(1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for Y<>\n" + + "----------\n" + + "6. ERROR in X.java (at line 25)\n" + + " X<Integer>.Y<String> y6 = new X<>().new Y<>(1,\"\",1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Object>.Y<Integer> to X<Integer>.Y<String>\n" + + "----------\n" + + "7. ERROR in X.java (at line 26)\n" + + " X<Integer>.Y<String> y7 = new X<>().new Y<>(\"\",\"\",1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Object>.Y<Integer> to X<Integer>.Y<String>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0036() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X(T t) {}\n" + + " X() {}\n" + + " @SafeVarargs\n" + + " X(String abc, String abc2, T... t) {}\n" + + " void foo(T a) {\n" + + " System.out.println(a);\n" + + " }\n" + + " class Y<K>{\n" + + " @SafeVarargs\n" + + " Y(T t,String abc, K... k) {}\n" + + " }\n" + + " X<Integer> x1 = new X<>(1,1);\n" + + " X<Integer> x2 = new X<>(1);\n" + + " X<Integer> x3 = new X<>();\n" + + " X<Integer> x4 = new X<>(\"\",\"\");\n" + + " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + + " X<Integer> x6 = new X<>(\"\",\"\",1);\n" + + " X<Integer>.Y<String> y1 = new X<>(1,1).new Y<>();\n" + + " X<Integer>.Y<String> y2 = new X<>(\"\",1).new Y<>(\"\");\n" + + " X<Integer>.Y<String> y3 = new X<>(1).new Y<>(1);\n" + + " X<Integer>.Y<String> y4 = new X<>(1).new Y<>(1,\"\");\n" + + " X<Integer>.Y<String> y5 = new X<>(1).new Y<>(1,\"\",\"\");\n" + + " X<Integer>.Y<String> y6 = new X<>().new Y<>(1,\"\",1);\n" + + " X<Integer>.Y<String> y7 = new X<>().new Y<>(\"\",\"\",1);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " X<Integer> x1 = new X<>(1,1);\n" + + " ^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<String> to X<Integer>\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " X<Integer>.Y<String> y1 = new X<>(1,1).new Y<>();\n" + + " ^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n" + + "4. ERROR in X.java (at line 20)\n" + + " X<Integer>.Y<String> y2 = new X<>(\"\",1).new Y<>(\"\");\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n" + + "5. ERROR in X.java (at line 21)\n" + + " X<Integer>.Y<String> y3 = new X<>(1).new Y<>(1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for Y<>\n" + + "----------\n" + + "6. ERROR in X.java (at line 24)\n" + + " X<Integer>.Y<String> y6 = new X<>().new Y<>(1,\"\",1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Object>.Y<Integer> to X<Integer>.Y<String>\n" + + "----------\n" + + "7. ERROR in X.java (at line 25)\n" + + " X<Integer>.Y<String> y7 = new X<>().new Y<>(\"\",\"\",1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Object>.Y<Integer> to X<Integer>.Y<String>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0034a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X(T t) {}\n" + + " X() {}\n" + + " void foo(T a) {\n" + + " System.out.println(a);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<Integer> x1 = new X<>(1,1);\n" + + " X<Integer> x2 = new X<>(1);\n" + + " X<Integer> x3 = new X<>();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " X<Integer> x1 = new X<>(1,1);\n" + + " ^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0035a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X(T t) {}\n" + + " X() {}\n" + + " @SafeVarargs\n" + + " X(String abc, String abc2, T... t) {}\n" + + " void foo(T a) {\n" + + " System.out.println(a);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<Integer> x1 = new X<>(1,1);\n" + + " X<Integer> x2 = new X<>(1);\n" + + " X<Integer> x3 = new X<>();\n" + + " X<Integer> x4 = new X<>(\"\",\"\");\n" + + " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + + " X<Integer> x6 = new X<>(\"\",\"\",1);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " X<Integer> x1 = new X<>(1,1);\n" + + " ^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<String> to X<Integer>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0036a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X(T t) {}\n" + + " X() {}\n" + + " @SafeVarargs\n" + + " X(String abc, String abc2, T... t) {}\n" + + " void foo(T a) {\n" + + " System.out.println(a);\n" + + " }\n" + + " X<Integer> x1 = new X<>(1,1);\n" + + " X<Integer> x2 = new X<>(1);\n" + + " X<Integer> x3 = new X<>();\n" + + " X<Integer> x4 = new X<>(\"\",\"\");\n" + + " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + + " X<Integer> x6 = new X<>(\"\",\"\",1);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " X<Integer> x1 = new X<>(1,1);\n" + + " ^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<String> to X<Integer>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0037() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " X(T t) {}\n" + + " X() {}\n" + + " @SafeVarargs\n" + + " X(String abc, String abc2, T... t) {}\n" + + " void foo(T a) {\n" + + " System.out.println(a);\n" + + " }\n" + + " class Y<K>{\n" + + " @SafeVarargs\n" + + " Y(T t,String abc, K... k) {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<Integer>.Y<String> y1 = new X<>().new Y<>(1);\n" + + " X<Integer>.Y<String> y2 = new X<>(1).new Y<>(1);\n" + + " X<Integer>.Y<String> y3 = new X<>(\"\",\"\",1).new Y<>(1);\n" + + " X<Integer>.Y<String> y4 = new X<>(1,\"\").new Y<>(1,\"\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " X<Integer>.Y<String> y1 = new X<>().new Y<>(1);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for Y<>\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " X<Integer>.Y<String> y2 = new X<>(1).new Y<>(1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for Y<>\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " X<Integer>.Y<String> y3 = new X<>(\"\",\"\",1).new Y<>(1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for Y<>\n" + + "----------\n" + + "4. ERROR in X.java (at line 17)\n" + + " X<Integer>.Y<String> y4 = new X<>(1,\"\").new Y<>(1,\"\");\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for X<>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=341795 +public void test0038() { + this.runConformTest( + new String[] { + "X.java", + "interface A {\n" + + " <T extends B & C> T getaMethod();\n" + + " <T extends B & C> void setaMethod(T param);\n" + + "}\n" + + "class B {\n" + + "}\n" + + "interface C {\n" + + "}\n" + + "public class X {\n" + + " public void someMethod(A aInstance) {\n" + + " aInstance.getaMethod();\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319436 +public void test0039() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " createObject();\n" + + " }\n" + + " private static <T extends Comparable<?> & Serializable> T createObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + ""); +} +public void test0042() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I<T> {}\n" + + "public class X {\n" + + " <T extends I<T>> void m() { }\n" + + " { m(); } \n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345968 +public void test0043() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class Y<Z> {\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String>.Y<String> x1 = new X<String>().new Y<String>(\"\",\"\");\n" + + " X<String>.Y<String> x2 = new X<String>().new Y<>(\"\",\"\");\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345968 +public void test0044() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class Y<Z> {\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String>.Y<String> x = new X<>().new Y<>(\"\",\"\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " X<String>.Y<String> x = new X<>().new Y<>(\"\",\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Object>.Y<String> to X<String>.Y<String>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345968 +public void test0045() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y<T, Z> {\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y<String, String> x = new X().new Y<>(\"\",\"\");\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345968 +public void test0046() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class Y<Z> {\n" + + " Y(T a, Z b) { \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String>.Y<String> x = new X<String>().new Y<>(\"\",\"\");\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345968 +public void test0047() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class Y<Z> {\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String>.Y<String> x1 = new X<String>().new Y<String>(\"\",\"\"); \n" + + " X<String>.Y<String> x2 = new X<String>().new Y<>(\"\",\"\"); // javac wrong error \n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345968 +public void test0048() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " <T> X(T t) {\n" + + " }\n" + + " X<String> x = new X<>(\"\"); \n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " <T> X(T t) {\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345968 +public void test0049() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T> {\n" + + " class Y<Z> {\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<Object>.Y<String> x1 = new X<Object>().new Y<String>(new Object(),\"\");\n" + + " X<Object>.Y<String> x2 = new X<>().new Y<String>(new Object(),\"\");\n" + + " X<Object>.Y<String> x3 = new X<Object>().new Y<>(new Object(),\"\");\n" + + " X<Object>.Y<String> x4 = new X<>().new Y<>(new Object(),\"\");\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345968 +public void test0050() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T extends Comparable<T>> {\n" + + " class Y<Z> {\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String>.Y<String> x1 = new X<String>().new Y<>(\"\",\"\");\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345968 +public void test0051() { + this.runConformTest( + new String[] { + "X.java", + "public class X<T extends Comparable<T>> {\n" + + " class Y<Z> {\n" + + " Y(Integer a, Z b) {\n" + + " }\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<String>.Y<String> x1 = new X<String>().new Y<>(\"\",\"\");\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +public void test0052() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X<E> {\n" + + " X(E e) {}\n" + + " X() {}\n" + + " public static void main(String[] args) {\n" + + " X<Number> x = new X<Number>(1);\n" + + " X<String> x2 = new X<String>(\"SUCCESS\");\n" + + " X<Integer> x3 = new X<Integer>(1);\n" + + " X<AX> x4 = new X<AX>(new AX());\n" + + " X<? extends AX> x5 = new X<AX<String>>(new AX<String>());\n" + + " X<?> x6 = new X<AX<String>>(new AX<String>());\n" + + " X<Class<? extends Object>> x7 = new X<Class<? extends Object>>();\n" + + " }\n" + + "}\n" + + "class AX<T>{}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X<String> x2 = new X<String>(\"SUCCESS\");\n" + + " ^\n" + + "Redundant specification of type arguments <String>\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " X<Integer> x3 = new X<Integer>(1);\n" + + " ^\n" + + "Redundant specification of type arguments <Integer>\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " X<AX> x4 = new X<AX>(new AX());\n" + + " ^\n" + + "Redundant specification of type arguments <AX>\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " X<? extends AX> x5 = new X<AX<String>>(new AX<String>());\n" + + " ^\n" + + "Redundant specification of type arguments <AX<String>>\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " X<?> x6 = new X<AX<String>>(new AX<String>());\n" + + " ^\n" + + "Redundant specification of type arguments <AX<String>>\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " X<Class<? extends Object>> x7 = new X<Class<? extends Object>>();\n" + + " ^\n" + + "Redundant specification of type arguments <Class<? extends Object>>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +public void test0052b() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X<E> {\n" + + " E eField;\n" + + " E get() { return this.eField; }\n" + + " X(E e) {}\n" + + " X(int e, String e2) {}\n" + + " public static void main(String[] args) {\n" + + " X<Number> x = new X<Number>(1);\n" + + " X<String> x2 = new X<String>(\"SUCCESS\");\n" + + " X<String> x22 = new X<String>(1,\"SUCCESS\");\n" + + " X<Integer> x3 = new X<Integer>(1);\n" + + " String s = foo(new X<String>(\"aaa\"));\n" + + " String s2 = foo(new X<String>(1,\"aaa\"));\n" + + " }\n" + + " static String foo(X<String> x) {\n" + + " return x.get();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " X<String> x2 = new X<String>(\"SUCCESS\");\n" + + " ^\n" + + "Redundant specification of type arguments <String>\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " X<String> x22 = new X<String>(1,\"SUCCESS\");\n" + + " ^\n" + + "Redundant specification of type arguments <String>\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " X<Integer> x3 = new X<Integer>(1);\n" + + " ^\n" + + "Redundant specification of type arguments <Integer>\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " String s = foo(new X<String>(\"aaa\"));\n" + + " ^\n" + + "Redundant specification of type arguments <String>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +public void test0052c() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X<E> {\n" + + " X(String abc, String def) {}\n" + + " void foo() {\n" + + " X<Integer> x = new X<Integer>(\"\",\"\");\n" + + " foo3(new X<Integer>(\"\",\"\"));\n" + + " }\n" + + " X<Integer> foo2() {\n" + + " return new X<Integer>(\"\",\"\");\n" + + " }\n" + + " void foo3(X<Integer> x) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X<Integer> x = new X<Integer>(\"\",\"\");\n" + + " ^\n" + + "Redundant specification of type arguments <Integer>\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return new X<Integer>(\"\",\"\");\n" + + " ^\n" + + "Redundant specification of type arguments <Integer>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +public void test0053() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "Z.java", + "public class Z <T extends ZB> { \n" + + " public static void main(String[] args) {\n" + + " foo(new Z<ZB>());\n" + + " }\n" + + " static void foo(Z<ZB> z) {\n" + + " }\n" + + "}\n" + + "class ZB {\n" + + "}" + }, + "----------\n" + + "1. ERROR in Z.java (at line 3)\n" + + " foo(new Z<ZB>());\n" + + " ^\n" + + "Redundant specification of type arguments <ZB>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +public void test0054() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y<V> {\n" + + " public static <W extends ABC> Y<W> make(Class<W> clazz) {\n" + + " return new Y<W>();\n" + + " }\n" + + "}\n" + + "class ABC{}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " return new Y<W>();\n" + + " ^\n" + + "Redundant specification of type arguments <W>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +public void test0055() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X<A> {\n" + + " class Inner<B> { }\n" + + " static class Inner2<C> { }\n" + + "\n" + + " void method() {\n" + + " X<String>.Inner<Integer> a= new X<String>().new Inner<Integer>();\n" + + " X<String>.Inner<Integer> a1= new X<String>().new Inner<>();\n" + // do not warn. Removing String from X<String> not possible + " Inner<Integer> b= new X<A>().new Inner<Integer>();\n" + + " Inner<Integer> c= new Inner<Integer>();\n" + + " X<A>.Inner<Integer> e= new X<A>().new Inner<Integer>();\n" + + " X<A>.Inner<Integer> f= new Inner<Integer>();\n" + + " X.Inner2<Integer> d3 = new X.Inner2<Integer>();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X<String>.Inner<Integer> a= new X<String>().new Inner<Integer>();\n" + + " ^^^^^\n" + + "Redundant specification of type arguments <Integer>\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Inner<Integer> b= new X<A>().new Inner<Integer>();\n" + + " ^^^^^\n" + + "Redundant specification of type arguments <Integer>\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Inner<Integer> c= new Inner<Integer>();\n" + + " ^^^^^\n" + + "Redundant specification of type arguments <Integer>\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " X<A>.Inner<Integer> e= new X<A>().new Inner<Integer>();\n" + + " ^^^^^\n" + + "Redundant specification of type arguments <Integer>\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " X<A>.Inner<Integer> f= new Inner<Integer>();\n" + + " ^^^^^\n" + + "Redundant specification of type arguments <Integer>\n" + + "----------\n" + + "6. ERROR in X.java (at line 12)\n" + + " X.Inner2<Integer> d3 = new X.Inner2<Integer>();\n" + + " ^^^^^^\n" + + "Redundant specification of type arguments <Integer>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +// qualified allocation +public void test0056() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X <T> {\n" + + " void foo1() {\n" + + " X<String>.Item<Thread> i = new X<Exception>().new Item<Thread>();\n" + + " }\n" + + " void foo2() {\n" + + " X<Exception>.Item<Thread> j = new X<Exception>.Item<Thread>();\n" + + " }\n" + + " class Item <E> {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X<String>.Item<Thread> i = new X<Exception>().new Item<Thread>();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X<Exception>.Item<Thread> to X<String>.Item<Thread>\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " X<String>.Item<Thread> i = new X<Exception>().new Item<Thread>();\n" + + " ^^^^\n" + + "Redundant specification of type arguments <Thread>\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " X<Exception>.Item<Thread> j = new X<Exception>.Item<Thread>();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot allocate the member type X<Exception>.Item<Thread> using a parameterized compound name; use its simple name and an enclosing instance of type X<Exception>\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " X<Exception>.Item<Thread> j = new X<Exception>.Item<Thread>();\n" + + " ^^^^\n" + + "Redundant specification of type arguments <Thread>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +// qualified allocation +public void test0056b() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X <T> {\n" + + " static class X1<Z> {\n" + + " X1(Z z){}\n" + + " }\n" + + " X1<Integer> x1 = new X.X1<Integer>(1);\n" + + " X1<Number> x2 = new X.X1<Number>(1);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X1<Integer> x1 = new X.X1<Integer>(1);\n" + + " ^^\n" + + "Redundant specification of type arguments <Integer>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +// qualified allocation +public void test0056c() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X <T> {\n" + + " X(T t){}\n" + + " class X1<Z> {\n" + + " X1(Z z){}\n" + + " }\n" + + " X<Integer>.X1<Number> x1 = new X<Integer>(1).new X1<Number>(1);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X<Integer>.X1<Number> x1 = new X<Integer>(1).new X1<Number>(1);\n" + + " ^\n" + + "Redundant specification of type arguments <Integer>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +public void test0057() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void test() {\n" + + " Pair<Double, Integer> p = new InvertedPair<Integer, Double>();\n" + + " }\n" + + "}\n" + + "class Pair<A, B> {\n" + + "}\n" + + "class InvertedPair<A, B> extends Pair<B, A> {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Pair<Double, Integer> p = new InvertedPair<Integer, Double>();\n" + + " ^^^^^^^^^^^^\n" + + "Redundant specification of type arguments <Integer, Double>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +public void test0058() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public void test(boolean param) {\n" + + " ArrayList<?> ls = (param) \n" + + " ? new ArrayList<String>()\n" + + " : new ArrayList<Object>();\n" + + " \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " : new ArrayList<Object>();\n" + + " ^^^^^^^^^\n" + + "Redundant specification of type arguments <Object>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +public void test0059() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X<T> {\n" + + " X(List<? extends T> p) {}\n" + + " Object x = new X<CharSequence>((ArrayList<String>) null);\n" + + "}\n" + }, + "", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=351965 +public void test0060() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public void foo() {\n" + + " new ArrayList<>();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new ArrayList<>();\n" + + " ^^^^^^^^^\n" + + "\'<>\' operator is not allowed for source level below 1.7\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " new ArrayList<>();\n" + + " ^^^^^^^^^\n" + + "Incorrect number of arguments for type ArrayList<E>; it cannot be parameterized with arguments <>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=351965 +public void test0060a() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + this.runNegativeTest( + new String[] { + "X.java", + "\n" + + "public class X {\n" + + " public void foo() {\n" + + " new java.util.ArrayList<>();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new java.util.ArrayList<>();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "\'<>\' operator is not allowed for source level below 1.7\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " new java.util.ArrayList<>();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Incorrect number of arguments for type ArrayList<E>; it cannot be parameterized with arguments <>\n" + + "----------\n", + null, + false, + customOptions); +} +public static Class testClass() { + return GenericsRegressionTest_1_7.class; +} +} diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_3.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_3.java index f46d4cbd8b..d3f0cbcfa6 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_3.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_3.java @@ -110,7 +110,7 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in X.java (at line 5)\r\n" + " public class X<E> {}\r\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -133,7 +133,7 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in X.java (at line 5)\r\n" + " public class X<E extends RuntimeException> {}\r\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); @@ -169,7 +169,7 @@ public class JavadocTest_1_3 extends JavadocTest { "4. ERROR in X.java (at line 7)\r\n" + " public class X<T, U, V> {}\r\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -210,7 +210,7 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in X.java (at line 5)\n" + " public class X<E, F> {}\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -245,7 +245,7 @@ public class JavadocTest_1_3 extends JavadocTest { "4. ERROR in X.java (at line 7)\n" + " public class X<T> {}\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -292,7 +292,7 @@ public class JavadocTest_1_3 extends JavadocTest { "6. ERROR in X.java (at line 9)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -327,7 +327,7 @@ public class JavadocTest_1_3 extends JavadocTest { "4. ERROR in X.java (at line 7)\r\n" + " public class X<T, U, V> {}\r\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -374,7 +374,7 @@ public class JavadocTest_1_3 extends JavadocTest { "6. ERROR in X.java (at line 9)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -391,7 +391,7 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in X.java (at line 4)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -414,7 +414,7 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in X.java (at line 5)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -437,7 +437,7 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in X.java (at line 5)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -466,7 +466,7 @@ public class JavadocTest_1_3 extends JavadocTest { "3. ERROR in X.java (at line 6)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -495,7 +495,7 @@ public class JavadocTest_1_3 extends JavadocTest { "3. ERROR in X.java (at line 6)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -524,7 +524,7 @@ public class JavadocTest_1_3 extends JavadocTest { "3. ERROR in X.java (at line 6)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -547,7 +547,7 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in X.java (at line 5)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -594,7 +594,7 @@ public class JavadocTest_1_3 extends JavadocTest { "6. ERROR in X.java (at line 9)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -629,7 +629,7 @@ public class JavadocTest_1_3 extends JavadocTest { "4. ERROR in X.java (at line 7)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -743,7 +743,7 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in X.java (at line 6)\r\n" + " public <E> void foo() {}\r\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -770,7 +770,7 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in X.java (at line 8)\r\n" + " public <E extends RuntimeException> void foo(int val, Object obj) {}\r\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -809,7 +809,7 @@ public class JavadocTest_1_3 extends JavadocTest { "4. ERROR in X.java (at line 10)\r\n" + " public <T, U, V> void foo(int val, Object obj) {}\r\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -856,7 +856,7 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in X.java (at line 6)\n" + " public <E, F> void foo(int val, Object obj) {}\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 6)\n" + " public <E, F> void foo(int val, Object obj) {}\n" + @@ -915,7 +915,7 @@ public class JavadocTest_1_3 extends JavadocTest { "6. ERROR in X.java (at line 10)\n" + " public <T> void foo(int val, Object obj) {}\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "7. ERROR in X.java (at line 10)\n" + " public <T> void foo(int val, Object obj) {}\n" + @@ -976,7 +976,7 @@ public class JavadocTest_1_3 extends JavadocTest { "6. ERROR in X.java (at line 12)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -1015,7 +1015,7 @@ public class JavadocTest_1_3 extends JavadocTest { "4. ERROR in X.java (at line 10)\r\n" + " public <T, U, V> void foo(int val, Object obj) {}\r\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -1034,7 +1034,7 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in X.java (at line 5)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 5)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + @@ -1070,7 +1070,7 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in X.java (at line 7)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 7)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + @@ -1107,7 +1107,7 @@ public class JavadocTest_1_3 extends JavadocTest { "3. ERROR in X.java (at line 8)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in X.java (at line 8)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + @@ -1174,7 +1174,7 @@ public class JavadocTest_1_3 extends JavadocTest { "8. ERROR in X.java (at line 13)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "9. ERROR in X.java (at line 13)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + @@ -1216,7 +1216,7 @@ public class JavadocTest_1_3 extends JavadocTest { "4. ERROR in X.java (at line 8)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in X.java (at line 8)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + @@ -1306,7 +1306,7 @@ public class JavadocTest_1_3 extends JavadocTest { "4. ERROR in X.java (at line 10)\n" + " public <T, U, V extends Exceptions> void foo(int val, Object obj) {}\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in X.java (at line 10)\n" + " public <T, U, V extends Exceptions> void foo(int val, Object obj) {}\n" + @@ -1358,7 +1358,7 @@ public class JavadocTest_1_3 extends JavadocTest { "6. ERROR in X.java (at line 9)\n" + " public class X<E> {}\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -1405,7 +1405,7 @@ public class JavadocTest_1_3 extends JavadocTest { "6. ERROR in X.java (at line 9)\n" + " public class X<E> {}\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -1451,12 +1451,12 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in X.java (at line 5)\n" + " public class X extends G<Exception> {\n" + " ^^^^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 8)\n" + " class G<E extends Exception> {\n" + " ^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -1491,17 +1491,17 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in X.java (at line 2)\n" + " public static <T extends Comparable< ? super T>> int compareTo(final Object first, final Object firstPrime, final Class<T> type) throws ClassCastException\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 2)\n" + " public static <T extends Comparable< ? super T>> int compareTo(final Object first, final Object firstPrime, final Class<T> type) throws ClassCastException\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 6)\n" + " public static <X extends Comparable< ? super X>> int compareTo(final X first, final X firstPrime)\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. WARNING in X.java (at line 6)\n" + " public static <X extends Comparable< ? super X>> int compareTo(final X first, final X firstPrime)\n" + @@ -1574,17 +1574,17 @@ public class JavadocTest_1_3 extends JavadocTest { "5. ERROR in Test.java (at line 11)\n" + " public class Test<T> {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "6. ERROR in Test.java (at line 18)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "7. ERROR in Test.java (at line 18)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug83127b() { @@ -1632,17 +1632,17 @@ public class JavadocTest_1_3 extends JavadocTest { "3. ERROR in Test.java (at line 11)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in Test.java (at line 18)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in Test.java (at line 18)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug83127c() { @@ -1687,17 +1687,17 @@ public class JavadocTest_1_3 extends JavadocTest { "3. ERROR in Test.java (at line 8)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in Test.java (at line 15)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in Test.java (at line 15)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug83127d() { @@ -1737,7 +1737,7 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in Unrelated1.java (at line 1)\n" + " public class Unrelated1<E extends Number> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in Test.java (at line 2)\n" + @@ -1753,17 +1753,17 @@ public class JavadocTest_1_3 extends JavadocTest { "3. ERROR in Test.java (at line 8)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in Test.java (at line 15)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in Test.java (at line 15)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug83127e() { @@ -1803,7 +1803,7 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in Unrelated1.java (at line 1)\n" + " public class Unrelated1<E extends Number> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in Test.java (at line 2)\n" + @@ -1819,17 +1819,17 @@ public class JavadocTest_1_3 extends JavadocTest { "3. ERROR in Test.java (at line 9)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in Test.java (at line 15)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in Test.java (at line 15)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug83127f() { @@ -1868,23 +1868,23 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in Unrelated1.java (at line 1)\n" + " public class Unrelated1<E extends Number> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in Test.java (at line 8)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in Test.java (at line 14)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in Test.java (at line 14)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -1926,7 +1926,7 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in Unrelated1.java (at line 1)\n" + " public class Unrelated1<E extends Number> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in Test.java (at line 2)\n" + @@ -1942,17 +1942,17 @@ public class JavadocTest_1_3 extends JavadocTest { "3. ERROR in Test.java (at line 9)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in Test.java (at line 16)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in Test.java (at line 16)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -1994,7 +1994,7 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in Unrelated2.java (at line 1)\n" + " public interface Unrelated2<E> {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in Test.java (at line 2)\n" + @@ -2005,17 +2005,17 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in Test.java (at line 10)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in Test.java (at line 17)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in Test.java (at line 17)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } @@ -2049,17 +2049,17 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in Test.java (at line 3)\r\n" + " public void foo(int a, int... args) {}\r\n" + " ^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in Test.java (at line 4)\r\n" + " public void foo(String... args) {}\r\n" + " ^^^^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in Test.java (at line 5)\r\n" + " public void foo(Exception str, boolean... args) {}\r\n" + " ^^^^^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -2090,17 +2090,17 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in Test.java (at line 3)\n" + " public void foo(int a, int... args) {}\n" + " ^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in Test.java (at line 4)\n" + " public void foo(String... args) {}\n" + " ^^^^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in Test.java (at line 5)\n" + " public void foo(Exception str, boolean... args) {}\n" + " ^^^^^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in Invalid.java (at line 2)\n" + @@ -2976,17 +2976,17 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in test\\X.java (at line 8)\n" + " public <T> G<T> foo(Class<T> stuffClass) {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in test\\X.java (at line 8)\n" + " public <T> G<T> foo(Class<T> stuffClass) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in test\\X.java (at line 8)\n" + " public <T> G<T> foo(Class<T> stuffClass) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in test\\X.java (at line 15)\n" + " * @param <T>\n" + @@ -2996,17 +2996,17 @@ public class JavadocTest_1_3 extends JavadocTest { "5. ERROR in test\\X.java (at line 19)\n" + " public <T extends Object> G<T> foo(Class<T> stuffClass);\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "6. ERROR in test\\X.java (at line 19)\n" + " public <T extends Object> G<T> foo(Class<T> stuffClass);\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "7. ERROR in test\\X.java (at line 19)\n" + " public <T extends Object> G<T> foo(Class<T> stuffClass);\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "8. ERROR in test\\X.java (at line 22)\n" + " * @param <T>\n" + @@ -3016,7 +3016,7 @@ public class JavadocTest_1_3 extends JavadocTest { "9. ERROR in test\\X.java (at line 24)\n" + " class G<T> {}\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug95521b() { @@ -3068,12 +3068,12 @@ public class JavadocTest_1_3 extends JavadocTest { "2. ERROR in test\\X.java (at line 9)\n" + " public <T> X(Class<T> classT) {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in test\\X.java (at line 9)\n" + " public <T> X(Class<T> classT) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in test\\X.java (at line 12)\n" + " * @param <T>\n" + @@ -3083,27 +3083,27 @@ public class JavadocTest_1_3 extends JavadocTest { "5. ERROR in test\\X.java (at line 16)\n" + " public <T> Class<T> foo(Class<T> classT) {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "6. ERROR in test\\X.java (at line 16)\n" + " public <T> Class<T> foo(Class<T> classT) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "7. ERROR in test\\X.java (at line 16)\n" + " public <T> Class<T> foo(Class<T> classT) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "8. ERROR in test\\X.java (at line 25)\n" + " public <T> Y(Class<T> classT) {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "9. ERROR in test\\X.java (at line 25)\n" + " public <T> Y(Class<T> classT) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "10. ERROR in test\\X.java (at line 25)\n" + " public <T> Y(Class<T> classT) {\n" + @@ -3113,17 +3113,17 @@ public class JavadocTest_1_3 extends JavadocTest { "11. ERROR in test\\X.java (at line 32)\n" + " public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "12. ERROR in test\\X.java (at line 32)\n" + " public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "13. ERROR in test\\X.java (at line 32)\n" + " public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } @@ -3150,7 +3150,7 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in X.java (at line 1)\n" + " public class X<T, F> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " * @param <T> \n" + @@ -3165,7 +3165,7 @@ public class JavadocTest_1_3 extends JavadocTest { "4. ERROR in X.java (at line 7)\n" + " static class Entry<L, R> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -3188,7 +3188,7 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in X.java (at line 1)\n" + " public class X<T, F> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " * @see T Variable \n" + @@ -3203,7 +3203,7 @@ public class JavadocTest_1_3 extends JavadocTest { "4. ERROR in X.java (at line 7)\n" + " static class Entry<L, R> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -3226,7 +3226,7 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in X.java (at line 1)\n" + " public class X<T, F> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " * @param <T> \n" + @@ -3241,7 +3241,7 @@ public class JavadocTest_1_3 extends JavadocTest { "4. ERROR in X.java (at line 7)\n" + " class Entry<L, R> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -3264,7 +3264,7 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in X.java (at line 1)\n" + " public class X<T, F> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " * @see T Variable \n" + @@ -3279,7 +3279,7 @@ public class JavadocTest_1_3 extends JavadocTest { "4. ERROR in X.java (at line 7)\n" + " class Entry<L, R> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -3357,7 +3357,7 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in Test.java (at line 6)\n" + " public class Test<T> {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n"); } @@ -3693,7 +3693,7 @@ public class JavadocTest_1_3 extends JavadocTest { "1. ERROR in TestClass.java (at line 1)\r\n" + " class TestClass<T> {\r\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_4.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_4.java index f613f335d1..263dd8da36 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_4.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_4.java @@ -111,7 +111,7 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in X.java (at line 5)\r\n" + " public class X<E> {}\r\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -134,7 +134,7 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in X.java (at line 5)\r\n" + " public class X<E extends RuntimeException> {}\r\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); @@ -170,7 +170,7 @@ public class JavadocTest_1_4 extends JavadocTest { "4. ERROR in X.java (at line 7)\r\n" + " public class X<T, U, V> {}\r\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -211,7 +211,7 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in X.java (at line 5)\n" + " public class X<E, F> {}\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -246,7 +246,7 @@ public class JavadocTest_1_4 extends JavadocTest { "4. ERROR in X.java (at line 7)\n" + " public class X<T> {}\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -293,7 +293,7 @@ public class JavadocTest_1_4 extends JavadocTest { "6. ERROR in X.java (at line 9)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -328,7 +328,7 @@ public class JavadocTest_1_4 extends JavadocTest { "4. ERROR in X.java (at line 7)\r\n" + " public class X<T, U, V> {}\r\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -375,7 +375,7 @@ public class JavadocTest_1_4 extends JavadocTest { "6. ERROR in X.java (at line 9)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -392,7 +392,7 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in X.java (at line 4)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -415,7 +415,7 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in X.java (at line 5)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -438,7 +438,7 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in X.java (at line 5)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -467,7 +467,7 @@ public class JavadocTest_1_4 extends JavadocTest { "3. ERROR in X.java (at line 6)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -496,7 +496,7 @@ public class JavadocTest_1_4 extends JavadocTest { "3. ERROR in X.java (at line 6)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -525,7 +525,7 @@ public class JavadocTest_1_4 extends JavadocTest { "3. ERROR in X.java (at line 6)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -548,7 +548,7 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in X.java (at line 5)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -595,7 +595,7 @@ public class JavadocTest_1_4 extends JavadocTest { "6. ERROR in X.java (at line 9)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -630,7 +630,7 @@ public class JavadocTest_1_4 extends JavadocTest { "4. ERROR in X.java (at line 7)\n" + " public class X<T, U, V> {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -744,7 +744,7 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in X.java (at line 6)\r\n" + " public <E> void foo() {}\r\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -771,7 +771,7 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in X.java (at line 8)\r\n" + " public <E extends RuntimeException> void foo(int val, Object obj) {}\r\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -810,7 +810,7 @@ public class JavadocTest_1_4 extends JavadocTest { "4. ERROR in X.java (at line 10)\r\n" + " public <T, U, V> void foo(int val, Object obj) {}\r\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -857,7 +857,7 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in X.java (at line 6)\n" + " public <E, F> void foo(int val, Object obj) {}\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 6)\n" + " public <E, F> void foo(int val, Object obj) {}\n" + @@ -916,7 +916,7 @@ public class JavadocTest_1_4 extends JavadocTest { "6. ERROR in X.java (at line 10)\n" + " public <T> void foo(int val, Object obj) {}\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "7. ERROR in X.java (at line 10)\n" + " public <T> void foo(int val, Object obj) {}\n" + @@ -977,7 +977,7 @@ public class JavadocTest_1_4 extends JavadocTest { "6. ERROR in X.java (at line 12)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -1016,7 +1016,7 @@ public class JavadocTest_1_4 extends JavadocTest { "4. ERROR in X.java (at line 10)\r\n" + " public <T, U, V> void foo(int val, Object obj) {}\r\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -1035,7 +1035,7 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in X.java (at line 5)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 5)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + @@ -1071,7 +1071,7 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in X.java (at line 7)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 7)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + @@ -1108,7 +1108,7 @@ public class JavadocTest_1_4 extends JavadocTest { "3. ERROR in X.java (at line 8)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in X.java (at line 8)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + @@ -1175,7 +1175,7 @@ public class JavadocTest_1_4 extends JavadocTest { "8. ERROR in X.java (at line 13)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "9. ERROR in X.java (at line 13)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + @@ -1217,7 +1217,7 @@ public class JavadocTest_1_4 extends JavadocTest { "4. ERROR in X.java (at line 8)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + " ^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in X.java (at line 8)\n" + " public <T, U, V> void foo(int val, Object obj) {}\n" + @@ -1307,7 +1307,7 @@ public class JavadocTest_1_4 extends JavadocTest { "4. ERROR in X.java (at line 10)\n" + " public <T, U, V extends Exceptions> void foo(int val, Object obj) {}\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in X.java (at line 10)\n" + " public <T, U, V extends Exceptions> void foo(int val, Object obj) {}\n" + @@ -1359,7 +1359,7 @@ public class JavadocTest_1_4 extends JavadocTest { "6. ERROR in X.java (at line 9)\n" + " public class X<E> {}\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -1406,7 +1406,7 @@ public class JavadocTest_1_4 extends JavadocTest { "6. ERROR in X.java (at line 9)\n" + " public class X<E> {}\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -1452,12 +1452,12 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in X.java (at line 5)\n" + " public class X extends G<Exception> {\n" + " ^^^^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 8)\n" + " class G<E extends Exception> {\n" + " ^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n"); } @@ -1491,17 +1491,17 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in X.java (at line 2)\n" + " public static <T extends Comparable< ? super T>> int compareTo(final Object first, final Object firstPrime, final Class<T> type) throws ClassCastException\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 2)\n" + " public static <T extends Comparable< ? super T>> int compareTo(final Object first, final Object firstPrime, final Class<T> type) throws ClassCastException\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 6)\n" + " public static <X extends Comparable< ? super X>> int compareTo(final X first, final X firstPrime)\n" + " ^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. WARNING in X.java (at line 6)\n" + " public static <X extends Comparable< ? super X>> int compareTo(final X first, final X firstPrime)\n" + @@ -1574,17 +1574,17 @@ public class JavadocTest_1_4 extends JavadocTest { "5. ERROR in Test.java (at line 11)\n" + " public class Test<T> {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "6. ERROR in Test.java (at line 18)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "7. ERROR in Test.java (at line 18)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug83127b() { @@ -1632,17 +1632,17 @@ public class JavadocTest_1_4 extends JavadocTest { "3. ERROR in Test.java (at line 11)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in Test.java (at line 18)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in Test.java (at line 18)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug83127c() { @@ -1687,17 +1687,17 @@ public class JavadocTest_1_4 extends JavadocTest { "3. ERROR in Test.java (at line 8)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in Test.java (at line 15)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in Test.java (at line 15)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug83127d() { @@ -1737,7 +1737,7 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in Unrelated1.java (at line 1)\n" + " public class Unrelated1<E extends Number> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in Test.java (at line 2)\n" + @@ -1753,17 +1753,17 @@ public class JavadocTest_1_4 extends JavadocTest { "3. ERROR in Test.java (at line 8)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in Test.java (at line 15)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in Test.java (at line 15)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug83127e() { @@ -1803,7 +1803,7 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in Unrelated1.java (at line 1)\n" + " public class Unrelated1<E extends Number> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in Test.java (at line 2)\n" + @@ -1819,17 +1819,17 @@ public class JavadocTest_1_4 extends JavadocTest { "3. ERROR in Test.java (at line 9)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in Test.java (at line 15)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in Test.java (at line 15)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug83127f() { @@ -1868,23 +1868,23 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in Unrelated1.java (at line 1)\n" + " public class Unrelated1<E extends Number> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in Test.java (at line 8)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in Test.java (at line 14)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in Test.java (at line 14)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug83127g() { @@ -1925,7 +1925,7 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in Unrelated1.java (at line 1)\n" + " public class Unrelated1<E extends Number> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in Test.java (at line 2)\n" + @@ -1941,17 +1941,17 @@ public class JavadocTest_1_4 extends JavadocTest { "3. ERROR in Test.java (at line 9)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in Test.java (at line 16)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in Test.java (at line 16)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } public void testBug83127h() { @@ -1992,7 +1992,7 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in Unrelated2.java (at line 1)\n" + " public interface Unrelated2<E> {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in Test.java (at line 2)\n" + @@ -2003,17 +2003,17 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in Test.java (at line 10)\n" + " public class Test<T>{\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in Test.java (at line 17)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in Test.java (at line 17)\n" + " class Sub<E extends Number> extends Test<E> {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n"); } @@ -2047,17 +2047,17 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in Test.java (at line 3)\r\n" + " public void foo(int a, int... args) {}\r\n" + " ^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in Test.java (at line 4)\r\n" + " public void foo(String... args) {}\r\n" + " ^^^^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in Test.java (at line 5)\r\n" + " public void foo(Exception str, boolean... args) {}\r\n" + " ^^^^^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -2088,17 +2088,17 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in Test.java (at line 3)\n" + " public void foo(int a, int... args) {}\n" + " ^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in Test.java (at line 4)\n" + " public void foo(String... args) {}\n" + " ^^^^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in Test.java (at line 5)\n" + " public void foo(Exception str, boolean... args) {}\n" + " ^^^^^^^^^^^^^^^\n" + - "Syntax error, varargs are only available if source level is 1.5\n" + + "Syntax error, varargs are only available if source level is 1.5 or greater\n" + "----------\n" + "----------\n" + "1. ERROR in Invalid.java (at line 2)\n" + @@ -2408,17 +2408,17 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in test\\X.java (at line 8)\n" + " public <T> G<T> foo(Class<T> stuffClass) {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in test\\X.java (at line 8)\n" + " public <T> G<T> foo(Class<T> stuffClass) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in test\\X.java (at line 8)\n" + " public <T> G<T> foo(Class<T> stuffClass) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in test\\X.java (at line 15)\n" + " * @param <T>\n" + @@ -2428,17 +2428,17 @@ public class JavadocTest_1_4 extends JavadocTest { "5. ERROR in test\\X.java (at line 19)\n" + " public <T extends Object> G<T> foo(Class<T> stuffClass);\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "6. ERROR in test\\X.java (at line 19)\n" + " public <T extends Object> G<T> foo(Class<T> stuffClass);\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "7. ERROR in test\\X.java (at line 19)\n" + " public <T extends Object> G<T> foo(Class<T> stuffClass);\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "8. ERROR in test\\X.java (at line 22)\n" + " * @param <T>\n" + @@ -2448,7 +2448,7 @@ public class JavadocTest_1_4 extends JavadocTest { "9. ERROR in test\\X.java (at line 24)\n" + " class G<T> {}\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -2501,12 +2501,12 @@ public class JavadocTest_1_4 extends JavadocTest { "2. ERROR in test\\X.java (at line 9)\n" + " public <T> X(Class<T> classT) {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in test\\X.java (at line 9)\n" + " public <T> X(Class<T> classT) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "4. ERROR in test\\X.java (at line 12)\n" + " * @param <T>\n" + @@ -2516,27 +2516,27 @@ public class JavadocTest_1_4 extends JavadocTest { "5. ERROR in test\\X.java (at line 16)\n" + " public <T> Class<T> foo(Class<T> classT) {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "6. ERROR in test\\X.java (at line 16)\n" + " public <T> Class<T> foo(Class<T> classT) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "7. ERROR in test\\X.java (at line 16)\n" + " public <T> Class<T> foo(Class<T> classT) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "8. ERROR in test\\X.java (at line 25)\n" + " public <T> Y(Class<T> classT) {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "9. ERROR in test\\X.java (at line 25)\n" + " public <T> Y(Class<T> classT) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "10. ERROR in test\\X.java (at line 25)\n" + " public <T> Y(Class<T> classT) {\n" + @@ -2546,17 +2546,17 @@ public class JavadocTest_1_4 extends JavadocTest { "11. ERROR in test\\X.java (at line 32)\n" + " public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "12. ERROR in test\\X.java (at line 32)\n" + " public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "13. ERROR in test\\X.java (at line 32)\n" + " public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + " ^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -3151,7 +3151,7 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in X.java (at line 1)\n" + " public class X<T, F> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " * @param <T> \n" + @@ -3166,7 +3166,7 @@ public class JavadocTest_1_4 extends JavadocTest { "4. ERROR in X.java (at line 7)\n" + " static class Entry<L, R> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -3189,7 +3189,7 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in X.java (at line 1)\n" + " public class X<T, F> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " * @see T Variable \n" + @@ -3204,7 +3204,7 @@ public class JavadocTest_1_4 extends JavadocTest { "4. ERROR in X.java (at line 7)\n" + " static class Entry<L, R> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -3227,7 +3227,7 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in X.java (at line 1)\n" + " public class X<T, F> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " * @param <T> \n" + @@ -3242,7 +3242,7 @@ public class JavadocTest_1_4 extends JavadocTest { "4. ERROR in X.java (at line 7)\n" + " class Entry<L, R> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -3265,7 +3265,7 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in X.java (at line 1)\n" + " public class X<T, F> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" + "2. ERROR in X.java (at line 4)\n" + " * @see T Variable \n" + @@ -3280,7 +3280,7 @@ public class JavadocTest_1_4 extends JavadocTest { "4. ERROR in X.java (at line 7)\n" + " class Entry<L, R> {\n" + " ^^^^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } @@ -3346,7 +3346,7 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in Test.java (at line 6)\n" + " public class Test<T> {\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n"); } @@ -3682,7 +3682,7 @@ public class JavadocTest_1_4 extends JavadocTest { "1. ERROR in TestClass.java (at line 1)\r\n" + " class TestClass<T> {\r\n" + " ^\n" + - "Syntax error, type parameters are only available if source level is 1.5\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + "----------\n" ); } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodHandleTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodHandleTest.java new file mode 100644 index 0000000000..d1013effa8 --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodHandleTest.java @@ -0,0 +1,306 @@ +/******************************************************************************* + * Copyright (c) 2011 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 + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.core.JavaCore; + +import junit.framework.Test; + +/** + * Regression test for MethodHandle.invokeExact(..)/invokeGeneric(..) invocation + */ +public class MethodHandleTest extends AbstractRegressionTest { + public MethodHandleTest(String name) { + super(name); + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_7); + } + + public static Class testClass() { + return MethodHandleTest.class; + } + + public void test001() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.invoke.MethodHandle;\n" + + "import java.lang.invoke.MethodHandles;\n" + + "import java.lang.invoke.MethodType;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " MethodHandles.Lookup lookup = MethodHandles.lookup();\n" + + "\n" + + " MethodType mt = MethodType.methodType(String.class, String.class, char.class);\n" + + " MethodHandle mh = lookup.findStatic(X.class, \"append\", mt);\n" + + " String s = (String) mh.invokeExact(\"follo\",'w');\n" + + " System.out.println(s);\n" + + "\n" + + " mt = MethodType.methodType(int.class, Object[].class);\n" + + " mh = lookup.findVirtual(X.class, \"arrayLength\", mt);\n" + + " int i = (int) mh.invokeExact(new X(), new Object[] {1, 'A', \"foo\"});\n" + + " System.out.println(i);\n" + + "\n" + + " mt = MethodType.methodType(void.class, String.class);\n" + + " mh = lookup.findStatic(X.class, \"hello\", mt);\n" + + " mh.invokeExact(\"world\");\n" + + "\n" + + " mt = MethodType.methodType(Object.class, String.class, int.class);\n" + + " mh = lookup.findVirtual(X.class, \"foo\", mt);\n" + + " Object o = mh.invokeGeneric(new X(), (Object)\"foo:\", i);\n" + + "\n" + + " mt = MethodType.methodType(void.class);\n" + + " mh = lookup.findStatic(X.class, \"bar\", mt);\n" + + " mh.invokeExact();\n" + + " }\n" + + " public static void bar() {\n" + + " System.out.println(\"bar\");\n" + + " }\n" + + " public Object foo(String s, int i) {\n" + + " System.out.println(s + i);\n" + + " return s + i;\n" + + " }\n" + + " public static String append(String s, char c) {\n" + + " return s + c;\n" + + " }\n" + + " public int arrayLength(Object[] array) {\n" + + " return array.length;\n" + + " }\n" + + " public static void hello(String name) {\n" + + " System.out.println(\"Hello, \"+ name);\n" + + " }\n" + + "}" + }, + "follow\n" + + "3\n" + + "Hello, world\n" + + "foo:3\n" + + "bar"); + } + public void test002() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.invoke.MethodHandle;\n" + + "import java.lang.invoke.MethodHandles;\n" + + "import java.lang.invoke.MethodType;\n" + + "import java.lang.invoke.WrongMethodTypeException;\n" + + "\n" + + "public class X {\n" + + " public static void foo() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " MethodHandle handle = MethodHandles.lookup().findStatic(X.class, \"foo\", MethodType.methodType(void.class));\n" + + " try {\n" + + " handle.invokeGeneric(null);\n" + + " } catch (WrongMethodTypeException ok) {\n" + + " System.out.println(\"This is ok\");\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}" + }, + "This is ok"); + } + public void test003() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.invoke.MethodHandle;\n" + + "import java.lang.invoke.MethodHandles;\n" + + "import java.lang.invoke.MethodType;\n" + + "import java.lang.invoke.WrongMethodTypeException;\n" + + "\n" + + "public class X {\n" + + " public static <T> T foo(T param){\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " MethodHandle handle = MethodHandles.lookup().findStatic(X.class, \"foo\", MethodType.methodType(Object.class, Object.class));\n" + + " try {\n" + + " handle.invokeGeneric(null);\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}" + }, + ""); + } + public void test004() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.invoke.MethodHandle;\n" + + "import java.lang.invoke.MethodHandles;\n" + + "import java.lang.invoke.MethodType;\n" + + "import java.lang.invoke.WrongMethodTypeException;\n" + + "\n" + + "public class X {\n" + + " public static <T> T foo(T param){\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " MethodHandle handle = MethodHandles.lookup().findStatic(X.class, \"foo\", MethodType.methodType(Object.class, Object.class));\n" + + " try {\n" + + " handle.invokeGeneric(new Object());\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}" + }, + ""); + } + public void test005() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.invoke.MethodHandle;\n" + + "import java.lang.invoke.MethodHandles;\n" + + "import java.lang.invoke.MethodType;\n" + + "import java.lang.invoke.WrongMethodTypeException;\n" + + "\n" + + "public class X {\n" + + " public static <T> T foo(T param){\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " MethodHandle handle = MethodHandles.lookup().findStatic(X.class, \"foo\", MethodType.methodType(Object.class, Object.class));\n" + + " try {\n" + + " Object o = handle.invokeGeneric(new Object());\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}" + }, + ""); + } + public void test006() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.invoke.MethodHandle;\n" + + "import java.lang.invoke.MethodHandles;\n" + + "import java.lang.invoke.MethodType;\n" + + "import java.lang.invoke.WrongMethodTypeException;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " MethodHandles.Lookup lookup = MethodHandles.lookup();\n" + + "\n" + + " MethodType mt = MethodType.methodType(String.class, String.class, char.class);\n" + + " MethodHandle mh = lookup.findStatic(X.class, \"append\", mt);\n" + + " String s = (String) mh.invokeExact(\"follo\",'w');\n" + + " System.out.println(s);\n" + + " MethodType mt2 = MethodType.methodType(String.class, String.class, char.class);\n" + + " MethodHandle mh2 = lookup.findStatic(X.class, \"append\", mt2);\n" + + " try {\n" + + " mh2.invokeExact(\"follo\",'w');\n" + + " } catch(WrongMethodTypeException e) {\n" + + " System.out.println(\"Expected exception\");\n" + + " }\n" + + " }\n" + + " public static String append(String s, char c) {\n" + + " return s + c;\n" + + " }\n" + + "}" + }, + "follow\n" + + "Expected exception"); + } + public void test007() { + this.runConformTest( + new String[] { + "X.java", + "import static java.lang.invoke.MethodHandles.lookup;\n" + + "import static java.lang.invoke.MethodType.methodType;\n" + + "import java.lang.invoke.MethodHandle;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " MethodHandle fooMH = lookup().findStatic(X.class, \"foo\", methodType(String.class));\n" + + " String s = (String) fooMH.invokeExact();\n" + + " System.out.println(s);\n" + + " fooMH.asType(methodType(void.class)).invokeExact();\n" + + " }\n" + + " public static String foo() {\n" + + " System.out.println(\"Inside foo\");\n" + + " return \"foo\";\n" + + " }\n" + + "}" + }, + "Inside foo\n" + + "foo\n" + + "Inside foo"); + } + public void test008() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_DEPRECATION, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.invoke.MethodHandle;\n" + + "import java.lang.invoke.MethodHandles;\n" + + "import java.lang.invoke.MethodType;\n" + + "import java.lang.invoke.WrongMethodTypeException;\n" + + "\n" + + "public class X {\n" + + " public static <T> T foo(T param){\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " MethodHandle handle = MethodHandles.lookup().findStatic(X.class, \"foo\", MethodType.methodType(Object.class, Object.class));\n" + + " try {\n" + + " Object o = handle.invokeGeneric(new Object());\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " Object o = handle.invokeGeneric(new Object());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method invokeGeneric(Object...) from the type MethodHandle is deprecated\n" + + "----------\n", + null, + true, + options); + } +} diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java index 285387f183..241c2aacca 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java @@ -2412,7 +2412,7 @@ public class MethodVerifyTest extends AbstractComparableTest { } public void test037() { // test inheritance scenarios - this.runConformTest( + this.runNegativeTest( new String[] { "X.java", "public abstract class X implements I, J { }\n" + @@ -2428,8 +2428,32 @@ public class MethodVerifyTest extends AbstractComparableTest { "interface K extends I { void foo(A<String> a); }\n" + "class A<T> {}" }, - "" - ); + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " class YYY implements J, I { public void foo(A a) {} }\n" + + " ^\n" + + "A is a raw type. References to generic type A<T> should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " class XXX implements I, J { public void foo(A a) {} }\n" + + " ^\n" + + "A is a raw type. References to generic type A<T> should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " class ZZZ implements K { public void foo(A a) {} }\n" + + " ^\n" + + "A is a raw type. References to generic type A<T> should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " interface I { void foo(A a); }\n" + + " ^\n" + + "A is a raw type. References to generic type A<T> should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " interface K extends I { void foo(A<String> a); }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A<String>) of type K has the same erasure as foo(A) of type I but does not override it\n" + + "----------\n"); } public void test037a() { // test inheritance scenarios this.runNegativeTest( @@ -2467,43 +2491,47 @@ public class MethodVerifyTest extends AbstractComparableTest { "interface K extends I { void foo(A<String> a); }\n" + "class A<T> {}" }, - "----------\n" + - "1. ERROR in XX.java (at line 1)\n" + - " public class XX implements I, J { public void foo(A<String> a) {} }\n" + - " ^^\n" + - "The type XX must implement the inherited abstract method I.foo(A)\n" + - "----------\n" + - "2. ERROR in XX.java (at line 1)\n" + - " public class XX implements I, J { public void foo(A<String> a) {} }\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(A<String>) of type XX has the same erasure as foo(A) of type I but does not override it\n" + - "----------\n" + - "3. ERROR in XX.java (at line 2)\n" + - " class YY implements J, I { public void foo(A<String> a) {} }\n" + - " ^^\n" + - "The type YY must implement the inherited abstract method I.foo(A)\n" + - "----------\n" + - "4. ERROR in XX.java (at line 2)\n" + - " class YY implements J, I { public void foo(A<String> a) {} }\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(A<String>) of type YY has the same erasure as foo(A) of type I but does not override it\n" + - "----------\n" + - "5. ERROR in XX.java (at line 3)\n" + - " class ZZ implements K { public void foo(A<String> a) {} }\n" + - " ^^\n" + - "The type ZZ must implement the inherited abstract method I.foo(A)\n" + - "----------\n" + - "6. ERROR in XX.java (at line 3)\n" + - " class ZZ implements K { public void foo(A<String> a) {} }\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Name clash: The method foo(A<String>) of type ZZ has the same erasure as foo(A) of type I but does not override it\n" + - "----------\n" + - "7. WARNING in XX.java (at line 4)\n" + - " interface I { void foo(A a); }\n" + - " ^\n" + - "A is a raw type. References to generic type A<T> should be parameterized\n" + + "----------\n" + + "1. ERROR in XX.java (at line 1)\n" + + " public class XX implements I, J { public void foo(A<String> a) {} }\n" + + " ^^\n" + + "The type XX must implement the inherited abstract method I.foo(A)\n" + + "----------\n" + + "2. ERROR in XX.java (at line 1)\n" + + " public class XX implements I, J { public void foo(A<String> a) {} }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A<String>) of type XX has the same erasure as foo(A) of type I but does not override it\n" + + "----------\n" + + "3. ERROR in XX.java (at line 2)\n" + + " class YY implements J, I { public void foo(A<String> a) {} }\n" + + " ^^\n" + + "The type YY must implement the inherited abstract method I.foo(A)\n" + + "----------\n" + + "4. ERROR in XX.java (at line 2)\n" + + " class YY implements J, I { public void foo(A<String> a) {} }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A<String>) of type YY has the same erasure as foo(A) of type I but does not override it\n" + + "----------\n" + + "5. ERROR in XX.java (at line 3)\n" + + " class ZZ implements K { public void foo(A<String> a) {} }\n" + + " ^^\n" + + "The type ZZ must implement the inherited abstract method I.foo(A)\n" + + "----------\n" + + "6. ERROR in XX.java (at line 3)\n" + + " class ZZ implements K { public void foo(A<String> a) {} }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A<String>) of type ZZ has the same erasure as foo(A) of type I but does not override it\n" + + "----------\n" + + "7. WARNING in XX.java (at line 4)\n" + + " interface I { void foo(A a); }\n" + + " ^\n" + + "A is a raw type. References to generic type A<T> should be parameterized\n" + + "----------\n" + + "8. ERROR in XX.java (at line 6)\n" + + " interface K extends I { void foo(A<String> a); }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A<String>) of type K has the same erasure as foo(A) of type I but does not override it\n" + "----------\n" - // XX/YY/ZZ is not abstract and does not override abstract method foo(A) in I ); } public void test037c() { // test inheritance scenarios @@ -2996,11 +3024,12 @@ public class MethodVerifyTest extends AbstractComparableTest { " public static <T> void foo(List<T>... e) {}\n" + "}\n" }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. WARNING in p\\X.java (at line 6)\n" + " public X() { foo(data.l); }\n" + " ^^^^^^^^^^^\n" + - "Type safety : A generic array of List<Object> is created for a varargs parameter\n" + + "Type safety: A generic array of List<Object> is created for a varargs parameter\n" + "----------\n" + "2. WARNING in p\\X.java (at line 6)\n" + " public X() { foo(data.l); }\n" + @@ -3017,7 +3046,40 @@ public class MethodVerifyTest extends AbstractComparableTest { " List l = null;\n" + " ^^^^\n" + "List is a raw type. References to generic type List<E> should be parameterized\n" + - "----------\n" + "----------\n" : + "----------\n" + + "1. WARNING in p\\X.java (at line 6)\n" + + " public X() { foo(data.l); }\n" + + " ^^^^^^^^^^^\n" + + "Type safety: A generic array of List<Object> is created for a varargs parameter\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 6)\n" + + " public X() { foo(data.l); }\n" + + " ^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(List) of the generic method foo(List<T>...) of type Z\n" + + "----------\n" + + "3. WARNING in p\\X.java (at line 6)\n" + + " public X() { foo(data.l); }\n" + + " ^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List<Object>\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\Y.java (at line 4)\n" + + " List l = null;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List<E> should be parameterized\n" + + "----------\n" + + "2. WARNING in p\\Y.java (at line 5)\n" + + " public static <T> void foo(T... e) {}\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter e\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\Z.java (at line 4)\n" + + " public static <T> void foo(List<T>... e) {}\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter e\n" + + "----------\n" // unchecked conversion warnings ); } @@ -3041,11 +3103,12 @@ public class MethodVerifyTest extends AbstractComparableTest { " public static <T> void foo(List<T>... e) {}\n" + "}\n" }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. WARNING in p\\X.java (at line 5)\n" + " public X() { foo(data.l); }\n" + " ^^^^^^^^^^^\n" + - "Type safety : A generic array of List<Object> is created for a varargs parameter\n" + + "Type safety: A generic array of List<Object> is created for a varargs parameter\n" + "----------\n" + "2. WARNING in p\\X.java (at line 5)\n" + " public X() { foo(data.l); }\n" + @@ -3062,7 +3125,39 @@ public class MethodVerifyTest extends AbstractComparableTest { " List l = null;\n" + " ^^^^\n" + "List is a raw type. References to generic type List<E> should be parameterized\n" + - "----------\n" + "----------\n" : + "----------\n" + + "1. WARNING in p\\X.java (at line 5)\n" + + " public X() { foo(data.l); }\n" + + " ^^^^^^^^^^^\n" + + "Type safety: A generic array of List<Object> is created for a varargs parameter\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 5)\n" + + " public X() { foo(data.l); }\n" + + " ^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(List) of the generic method foo(List<T>...) of type Y\n" + + "----------\n" + + "3. WARNING in p\\X.java (at line 5)\n" + + " public X() { foo(data.l); }\n" + + " ^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List<Object>\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\Y.java (at line 4)\n" + + " List l = null;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List<E> should be parameterized\n" + + "----------\n" + + "2. WARNING in p\\Y.java (at line 5)\n" + + " public static <T> void foo(T... e) {}\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter e\n" + + "----------\n" + + "3. WARNING in p\\Y.java (at line 6)\n" + + " public static <T> void foo(List<T>... e) {}\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter e\n" + + "----------\n" // unchecked conversion warnings ); } @@ -8552,6 +8647,7 @@ public void test143() { ""); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=194034 +// See that this test case exhibits the bug 345947 public void test144() { this.runNegativeTest( new String[] { @@ -8569,11 +8665,16 @@ public void test144() { "}\n" + "class PurebredCatShopImpl extends CatShopImpl implements PurebredCatShop {}" }, - "----------\n" + - "1. WARNING in PurebredCatShopImpl.java (at line 10)\n" + - " public List<Pet> getPets() { return null; }\n" + - " ^^^^\n" + - "Type safety: The return type List<Pet> for getPets() from the type CatShopImpl needs unchecked conversion to conform to List<? extends Cat> from the type CatShop\n" + + "----------\n" + + "1. ERROR in PurebredCatShopImpl.java (at line 6)\n" + + " <V extends Pet> List<? extends Cat> getPets();\n" + + " ^^^^^^^^^\n" + + "Name clash: The method getPets() of type CatShop has the same erasure as getPets() of type PetShop but does not override it\n" + + "----------\n" + + "2. WARNING in PurebredCatShopImpl.java (at line 10)\n" + + " public List<Pet> getPets() { return null; }\n" + + " ^^^^\n" + + "Type safety: The return type List<Pet> for getPets() from the type CatShopImpl needs unchecked conversion to conform to List<? extends Cat> from the type CatShop\n" + "----------\n" ); } @@ -9154,18 +9255,22 @@ public void test159() { "abstract class Y extends X {}\n" + "class Z extends X {}", }, - "----------\n" + - "1. ERROR in X.java (at line 15)\n" + - " public abstract class X extends Root implements AFoo, BFoo {}\n" + - " ^\n" + - "The return types are incompatible for the inherited methods BFoo.bar(), AFoo.bar()\n" + - "----------\n" + - "2. ERROR in X.java (at line 17)\n" + - " class Z extends X {}\n" + - " ^\n" + - "The type Z must implement the inherited abstract method AFoo.bar()\n" + - "----------\n" - ); + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " public abstract class X extends Root implements AFoo, BFoo {}\n" + + " ^\n" + + "The return types are incompatible for the inherited methods BFoo.bar(), AFoo.bar()\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " abstract class Y extends X {}\n" + + " ^\n" + + "The return types are incompatible for the inherited methods BFoo.bar(), AFoo.bar()\n" + + "----------\n" + + "3. ERROR in X.java (at line 17)\n" + + " class Z extends X {}\n" + + " ^\n" + + "The type Z must implement the inherited abstract method AFoo.bar()\n" + + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=208010 public void test160() { @@ -11996,4 +12101,231 @@ public void test339447() throws Exception { assertEquals("Wrong contents", expectedOutput, result); } } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322740 +public void test322740() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class Base {\n" + + " boolean equalTo(Object other) {return false;}\n" + + "}\n" + + "interface EqualityComparable<T> {\n" + + " boolean equalTo(T other);\n" + + "}\n" + + "public class X extends Base implements EqualityComparable<String> {\n" + + " public boolean equalTo(String other) {\n" + + " return true;\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " new X().equalTo(args);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public class X extends Base implements EqualityComparable<String> {\n" + + " ^\n" + + "Name clash: The method equalTo(T) of type EqualityComparable<T> has the same erasure as equalTo(Object) of type Base but does not override it\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334306 +public void test334306() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class X<T> {}\n" + + "interface I {\n" + + " void foo(X<Number> p);\n" + + "}\n" + + "interface J extends I {\n" + + " void foo(X<Integer> p);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " void foo(X<Integer> p);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(X<Integer>) of type J has the same erasure as foo(X<Number>) of type I but does not override it\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=342819 +public void test342819() throws Exception { + this.runNegativeTest( + new String[] { + "TwoWayDTOAdapter.java", + "public interface TwoWayDTOAdapter<A, B> extends DTOAdapter <A, B>{\n" + + " public A convert(B b);\n" + + "}\n", + "DTOAdapter.java", + "public interface DTOAdapter<A, B> {\n" + + " public B convert(A a);\n" + + "}\n", + "TestAdapter.java", + "public class TestAdapter implements TwoWayDTOAdapter<Long, Integer> {\n" + + " public Long convert(Integer b) {\n" + + " return null;\n" + + " }\n" + + " public Integer convert(Long a) {\n" + + " return null;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in TwoWayDTOAdapter.java (at line 2)\n" + + " public A convert(B b);\n" + + " ^^^^^^^^^^^^\n" + + "Name clash: The method convert(B) of type TwoWayDTOAdapter<A,B> has the same erasure as convert(A) of type DTOAdapter<A,B> but does not override it\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346029 +public void test346029() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class A<T> {\n" + + " void f(String s) {}\n" + + "}\n" + + "class B<T> extends A<T> {\n" + + " void f(T t) {}\n" + + "}\n" + + "public class X extends B<String> {\n" + + " void foo(X x) {\n" + + " x.f(\"\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public class X extends B<String> {\n" + + " ^\n" + + "Duplicate methods named f with the parameters (T) and (String) are inherited from the types B<String> and A<String>\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " x.f(\"\");\n" + + " ^\n" + + "The method f(String) is ambiguous for the type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346029 +public void test346029b() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface A<T> {\n" + + " void f(String s);\n" + + "}\n" + + "interface B<T> extends A<T> {\n" + + " void f(T t);\n" + + "}\n" + + "public class X implements B<String> {\n" + + " public void f(String t) {\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346029 +public void test346029c() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class A<T> {\n" + + " void f(String s) {}\n" + + "}\n" + + "interface B<T> {\n" + + " void f(T t);\n" + + "}\n" + + "public class X extends A<String> implements B<String> {\n" + + " public void f(String t) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " public void f(String t) {\n" + + " ^^^^^^^^^^^\n" + + "The method f(String) of type X should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=346029 +public void test346029d() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class A<T> {\n" + + " void f(T s) {}\n" + + "}\n" + + "interface B<T> {\n" + + " void f(String t);\n" + + "}\n" + + "public class X extends A<String> implements B<String> {\n" + + " public void f(String t) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " public void f(String t) {\n" + + " ^^^^^^^^^^^\n" + + "The method f(String) of type X should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346029 +public void test346029e() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class A<T> {\n" + + " void f(String s) {}\n" + + "}\n" + + "class B<T> extends A<T> {\n" + + " void f(T t) {}\n" + + "}\n" + + "public class X extends B<String> {\n" + + " void f(String s) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " void f(String s) {\n" + + " ^^^^^^^^^^^\n" + + "The method f(String) of type X should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346029 +public void test346029f() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class A<T> {\n" + + " void f(String s) {}\n" + + "}\n" + + "class B<T> extends A<T> {\n" + + " void f(T t) {}\n" + + "}\n" + + "public class X extends B<String> {\n" + + " void f(String s) {\n" + + " super.f(s);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " void f(String s) {\n" + + " ^^^^^^^^^^^\n" + + "The method f(String) of type X should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " super.f(s);\n" + + " ^\n" + + "The method f(String) is ambiguous for the type B<String>\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 851c117e27..6a4334ce56 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 @@ -44,7 +44,7 @@ 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[] { "testBug339250" }; +// TESTS_NAMES = new String[] { "testBug348379" }; // TESTS_NUMBERS = new int[] { 561 }; // TESTS_RANGE = new int[] { 1, 2049 }; } @@ -6357,6 +6357,162 @@ public void test0572_if_statement() { "The local variable i may not have been initialized\n" + "----------\n"); } + +// take care for Java7 changes +public void test0573_try_catch_unchecked_and_checked_exception() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " try {\n" + + " bar();\n" + + " o = new Object();\n" + + " } catch (IOException e) {\n" + + " o.toString();\n" + + " } catch(RuntimeException e) {\n" + + " o.toString();\n" + // may be null + " }\n" + + " }\n" + + " private Object bar() throws IOException{\n" + + " return new Object();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// similar to test0573 using multi catch parameters +public void test0574_try_multi_catch_unchecked_and_checked_exception() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " try {\n" + + " bar();\n" + + " o = new Object();\n" + + " } catch (IOException | RuntimeException e) {\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + " private Object bar() throws IOException{\n" + + " return new Object();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} +//multi catch variant of test0561_try_catch_unchecked_exception +public void test0575_try_multi_catch_finally_unchecked_and_checked_exception() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " try {\n" + + " o = bar();\n" + + " } catch (IOException | RuntimeException e) {\n" + + " o.toString();\n" + // may be null + " } finally {}\n" + + " }\n" + + " private Object bar() throws IOException{\n" + + " return new Object();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// null test for resources inside try with resources statement +public void test0576_try_with_resources() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "import java.io.FileNotFoundException;\n" + + "class MyException extends Exception {}\n" + + "public class X {\n" + + " static void m(int n) throws IllegalArgumentException, MyException {}\n" + + " void foo(String name, boolean b) throws FileNotFoundException, IOException{\n" + + " FileInputStream fis;\n" + + " if (b) fis = new FileInputStream(\"\");\n" + + " else fis = null;\n" + + " try (FileInputStream fis2 = fis; FileInputStream fis3 = fis2; FileInputStream fis4 = null) {\n" + + " fis = new FileInputStream(\"\");\n" + + " fis2.available();\n" + // may be null since fis may be null + " fis3.close();\n" + + " fis4.available();\n" + // will always be null + " m(1);\n" + + " } catch (IllegalArgumentException e) {\n" + + " fis.available();\n" + // may be null + " } catch (MyException e) {\n" + + " fis.available();\n" + // cannot be null + " } finally {}\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " class MyException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class MyException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " fis2.available();\n" + + " ^^^^\n" + + "Potential null pointer access: The variable fis2 may be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " fis3.close();\n" + + " ^^^^\n" + + "Potential null pointer access: The variable fis3 may be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " fis4.available();\n" + + " ^^^^\n" + + "Null pointer access: The variable fis4 can only be null at this location\n" + + "----------\n" + + "5. ERROR in X.java (at line 18)\n" + + " fis.available();\n" + + " ^^^\n" + + "Potential null pointer access: The variable fis may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + // null analysis - throw // https://bugs.eclipse.org/bugs/show_bug.cgi?id=201182 public void test0595_throw() { @@ -13847,8 +14003,8 @@ public void testBug333089() { ""); } -// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop -// original issue +//Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop +//original issue public void testBug336428() { this.runConformTest( new String[] { @@ -13865,9 +14021,9 @@ public void testBug336428() { }, ""); } -// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop -// hitting the same implementation branch from within the loop -// information from unknown o1 is not propagated into the loop, analysis currently believes o2 is def null. +//Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop +//hitting the same implementation branch from within the loop +//information from unknown o1 is not propagated into the loop, analysis currently believes o2 is def null. public void _testBug336428a() { this.runConformTest( new String[] { @@ -13887,8 +14043,8 @@ public void _testBug336428a() { ""); } -// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop -// in this variant the analysis believes o2 is def unknown and doesn't even consider raising a warning. +//Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop +//in this variant the analysis believes o2 is def unknown and doesn't even consider raising a warning. public void _testBug336428b() { this.runNegativeTest( new String[] { @@ -13911,8 +14067,8 @@ public void _testBug336428b() { "----------\n"); } -// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop -// in this case considering o1 as unknown is correct +//Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop +//in this case considering o1 as unknown is correct public void testBug336428c() { if (this.complianceLevel >= ClassFileConstants.JDK1_5) { this.runConformTest( @@ -13931,8 +14087,8 @@ public void testBug336428c() { } } -// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop -// one more if-statement triggers the expected warnings +//Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop +//one more if-statement triggers the expected warnings public void testBug336428d() { this.runNegativeTest( new String[] { @@ -13962,8 +14118,8 @@ public void testBug336428d() { "----------\n"); } -// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop -// same analysis, but assert instead of if suppresses the warning +//Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop +//same analysis, but assert instead of if suppresses the warning public void testBug336428e() { if (this.complianceLevel >= ClassFileConstants.JDK1_5) { this.runNegativeTest( @@ -14578,4 +14734,168 @@ public void testBug342300b() throws Exception { "----------\n"); } } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348379 +public void testBug348379a() throws Exception { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " String s = null;\n" + + " switch(s) {\n" + + " case \"abcd\":\n" + + " System.out.println(\"abcd\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"oops\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " switch(s) {\n" + + " ^\n" + + "Null pointer access: The variable s can only be null at this location\n" + + "----------\n"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348379 +public void testBug348379b() throws Exception { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = \"abcd\";\n" + + " switch(s) {\n" + // no warning since s is not null + " case \"abcd\":\n" + + " System.out.println(\"abcd\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"oops\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }, + "abcd"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348379 +public void testBug348379c() throws Exception { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String s) {\n" + + " if (s == null) {}\n" + // tainting s + " switch(s) {\n" + + " case \"abcd\":\n" + + " System.out.println(\"abcd\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"oops\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " switch(s) {\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348379 +public void testBug348379d() throws Exception { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String s) {\n" + + " if (s != null) {}\n" + // tainting s + " switch(s) {\n" + + " case \"abcd\":\n" + + " System.out.println(\"abcd\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"oops\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " switch(s) {\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348379 +public void testBug348379e() throws Exception { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String s) {\n" + + " if (s == null) {}\n" + // tainting s + " else\n" + + " switch(s) {\n" + // no warning because we're inside else + " case \"abcd\":\n" + + " System.out.println(\"abcd\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"oops\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }, + ""); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348379 +public void testBug348379f() throws Exception { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String s) {\n" + + " s = null;\n" + + " switch(s) {\n" + + " case \"abcd\":\n" + + " System.out.println(\"abcd\");\n" + + " break;\n" + + " default:\n" + + " switch(s) {\n" + // do not warn again + " case \"abcd\":\n" + + " System.out.println(\"abcd\");\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " switch(s) {\n" + + " ^\n" + + "Null pointer access: The variable s can only be null at this location\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/PolymorphicSignatureTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PolymorphicSignatureTest.java new file mode 100644 index 0000000000..6c60003de0 --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PolymorphicSignatureTest.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2011 IBM Corporation. + * 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 + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +public class PolymorphicSignatureTest extends AbstractRegressionTest { + public PolymorphicSignatureTest(String name) { + super(name); + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_7); + } + public static Class testClass() { + return PolymorphicSignatureTest.class; + } + + public void test0001() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.invoke.*; \n" + + "public class X {\n" + + " public static void main(String[] args) throws Throwable{\n" + + " MethodType mt; MethodHandle mh; \n" + + " MethodHandles.Lookup lookup = MethodHandles.lookup();\n" + + " mt = MethodType.methodType(String.class, char.class, char.class);\n"+ + " mh = lookup.findVirtual(String.class, \"replace\", mt);\n"+ + " String s = (String) mh.invokeExact(\"daddy\",'d','n');\n"+ + " System.out.println(s);\n"+ + " }\n" + + "}\n" + }, + "nanny"); + } +} 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 4c1ba197d5..a551aa001c 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 @@ -3403,12 +3403,12 @@ public void test074() { "6. ERROR in X.java (at line 9)\n" + " Zork<String> bar1() {}\n" + " ^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "7. ERROR in X.java (at line 10)\n" + " List<Zork> bar2() {}\n" + " ^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "8. ERROR in X.java (at line 10)\n" + " List<Zork> bar2() {}\n" + @@ -3423,7 +3423,7 @@ public void test074() { "10. ERROR in X.java (at line 11)\n" + " void bar3(Zork<String> z) {}\n" + " ^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "11. ERROR in X.java (at line 12)\n" + " void bar4(Zork<String,String> z) {}\n" + @@ -3433,7 +3433,7 @@ public void test074() { "12. ERROR in X.java (at line 12)\n" + " void bar4(Zork<String,String> z) {}\n" + " ^^^^^^^^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" : "----------\n" + "1. ERROR in X.java (at line 4)\n" + @@ -3508,7 +3508,7 @@ public void test075() { "2. ERROR in X.java (at line 3)\n" + " Zork<?,?> z = (Zork<?, ? extends Number>) o;\n" + " ^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 3)\n" + " Zork<?,?> z = (Zork<?, ? extends Number>) o;\n" + @@ -3518,7 +3518,7 @@ public void test075() { "4. ERROR in X.java (at line 3)\n" + " Zork<?,?> z = (Zork<?, ? extends Number>) o;\n" + " ^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in X.java (at line 4)\n" + " String s = (Zork<?, ? extends Number>) o;\n" + @@ -3533,7 +3533,7 @@ public void test075() { "7. ERROR in X.java (at line 4)\n" + " String s = (Zork<?, ? extends Number>) o;\n" + " ^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" : "----------\n" + "1. ERROR in X.java (at line 3)\n" + @@ -3591,7 +3591,7 @@ public void test076() { "2. ERROR in X.java (at line 3)\n" + " Zork<?,?> z = (Zork<?, ? super Number>) o;\n" + " ^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 3)\n" + " Zork<?,?> z = (Zork<?, ? super Number>) o;\n" + @@ -3601,7 +3601,7 @@ public void test076() { "4. ERROR in X.java (at line 3)\n" + " Zork<?,?> z = (Zork<?, ? super Number>) o;\n" + " ^^^^^^^^^^^^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in X.java (at line 4)\n" + " String s = (Zork<?, ? super Number>) o;\n" + @@ -3616,7 +3616,7 @@ public void test076() { "7. ERROR in X.java (at line 4)\n" + " String s = (Zork<?, ? super Number>) o;\n" + " ^^^^^^^^^^^^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" : "----------\n" + "1. ERROR in X.java (at line 3)\n" + @@ -3674,7 +3674,7 @@ public void test077() { "2. ERROR in X.java (at line 3)\n" + " Zork<?,?> z = (Zork<?, ? super Number[]>) o;\n" + " ^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "3. ERROR in X.java (at line 3)\n" + " Zork<?,?> z = (Zork<?, ? super Number[]>) o;\n" + @@ -3684,7 +3684,7 @@ public void test077() { "4. ERROR in X.java (at line 3)\n" + " Zork<?,?> z = (Zork<?, ? super Number[]>) o;\n" + " ^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" + "5. ERROR in X.java (at line 4)\n" + " String s = (Zork<?, ? extends Number[]>) o;\n" + @@ -3699,7 +3699,7 @@ public void test077() { "7. ERROR in X.java (at line 4)\n" + " String s = (Zork<?, ? extends Number[]>) o;\n" + " ^^^^^^^^^^^^^^^^^^^^^\n" + - "Syntax error, parameterized types are only available if source level is 1.5\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + "----------\n" : "----------\n" + "1. ERROR in X.java (at line 3)\n" + diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java index 0a438cc726..afe429ee39 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java @@ -2356,8 +2356,6 @@ public void test0057() throws Exception { } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=336648 public void _test0058() { - if (this.complianceLevel < ClassFileConstants.JDK1_5) - return; Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); this.runNegativeTest( @@ -2377,12 +2375,7 @@ public void _test0058() { "}\n" }, "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " final String message= m;\n" + - " ^^^^^^^\n" + - "The value of the local variable message is not used\n" + - "----------\n" + - "2. ERROR in X.java (at line 7)\n" + + "1. ERROR in X.java (at line 7)\n" + " bug(); // undefined method\n" + " ^^^\n" + "The method bug() is undefined for the type new Runnable(){}\n" + diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java index 846c5cafb7..84f81da7b5 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -31,8 +31,8 @@ public class ScannerTest extends AbstractRegressionTest { // All specified tests which does not belong to the class are skipped... static { // TESTS_NAMES = new String[] { "test000" }; -// TESTS_NUMBERS = new int[] { 53 }; -// TESTS_RANGE = new int[] { 11, -1 }; +// TESTS_NUMBERS = new int[] { 58 }; +// TESTS_RANGE = new int[] { 54, -1 }; } public static Test suite() { @@ -191,15 +191,11 @@ public class ScannerTest extends AbstractRegressionTest { char[] source = "0x11aa.aap-3333f".toCharArray(); //$NON-NLS-1$ scanner.setSource(source); scanner.resetTo(0, source.length - 1); - int counter = 0; try { - while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { - counter++; - } + scanner.getNextToken(); } catch (InvalidInputException e) { - assertTrue(false); + assertEquals("Wrong message", PublicScanner.ILLEGAL_HEXA_LITERAL, e.getMessage()); } - assertEquals("Wrong number of tokens", 5, counter); } /* @@ -1140,4 +1136,158 @@ public class ScannerTest extends AbstractRegressionTest { assertTrue("Should not fail with InvalidInputException", false); } } + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=340513 + */ + public void test054() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_6, JavaCore.VERSION_1_6); + char[] source = + ("class X {\n" + + " public static void main(String[] args) {\n" + + " String \ud804\udc09 = \"Brahmi\";\n" + + " System.out.println(\ud804\udc09);\n" + + " }\n" + + "}").toCharArray(); + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + int token; + boolean foundError = false; + while ((token = scanner.getNextToken()) != ITerminalSymbols.TokenNameEOF) { + foundError |= token == ITerminalSymbols.TokenNameERROR; + } + assertTrue("Did not find error token", foundError); + } catch (InvalidInputException e) { + assertTrue(false); + } + } + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=340513 + */ + public void test055() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_7, JavaCore.VERSION_1_7); + char[] source = + ("class X {\n" + + " public static void main(String[] args) {\n" + + " String \ud804\udc09 = \"Brahmi\";\n" + + " System.out.println(\ud804\udc09);\n" + + " }\n" + + "}").toCharArray(); + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + int token; + while ((token = scanner.getNextToken()) != ITerminalSymbols.TokenNameEOF) { + assertFalse("found error token", token == ITerminalSymbols.TokenNameERROR); + } + } catch (InvalidInputException e) { + assertTrue(false); + } + } + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=340513 + */ + public void test056() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_6, JavaCore.VERSION_1_6); + char[] source = + ("class X {\n" + + " public static void main(String[] args) {\n" + + " String \u20B9 = \"Rupee symbol\";\n" + + " System.out.println(\u20B9);\n" + + " }\n" + + "}").toCharArray(); + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + int token; + boolean foundError = false; + while ((token = scanner.getNextToken()) != ITerminalSymbols.TokenNameEOF) { + foundError |= token == ITerminalSymbols.TokenNameERROR; + } + assertTrue("Did not find error token", foundError); + } catch (InvalidInputException e) { + assertTrue(false); + } + } + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=340513 + */ + public void test057() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_7, JavaCore.VERSION_1_7); + char[] source = + ("class X {\n" + + " public static void main(String[] args) {\n" + + " String \u20B9 = \"Rupee symbol\";\n" + + " System.out.println(\u20B9);\n" + + " }\n" + + "}").toCharArray(); + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + int token; + while ((token = scanner.getNextToken()) != ITerminalSymbols.TokenNameEOF) { + assertFalse("found error token", token == ITerminalSymbols.TokenNameERROR); + } + } catch (InvalidInputException e) { + assertTrue(false); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=352014 + public void test058() { + String source = + "public class X {\n" + + " void foo() {\n" + + " int a\\u1369b;\n" + + " }\n" + + "}"; + if (this.complianceLevel <= ClassFileConstants.JDK1_6) { + this.runConformTest( + new String[] { + "X.java", + source + }, + ""); + } else { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int a\\u1369b;\n" + + " ^^^^^^\n" + + "Syntax error on token \"Invalid Character\", = expected\n" + + "----------\n"); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=352553 + public void test059() { + String source = + "public class X {\n" + + " void foo() {\n" + + " int a\\u200B;\n" + + " }\n" + + "}"; + if (this.complianceLevel > ClassFileConstants.JDK1_6) { + this.runConformTest( + new String[] { + "X.java", + source + }, + ""); + } else { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int a\\u200B;\n" + + " ^^^^^^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n"); + } + } } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerialVersionUIDTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerialVersionUIDTests.java index 70e03e85df..10ba9c7ac6 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerialVersionUIDTests.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerialVersionUIDTests.java @@ -262,15 +262,14 @@ public void test013() { this.runNegativeTest( new String[] { "X.java", - "import java.io.ObjectStreamField;\n" + "public class X<T> {\n" + - " private final static ObjectStreamField[] serialPersistentFields = null;\n" + + " private static final long serialPersistentFields = 1L;\n" + "}" }, "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " private final static ObjectStreamField[] serialPersistentFields = null;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "1. ERROR in X.java (at line 2)\n" + + " private static final long serialPersistentFields = 1L;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + "The value of the field X<T>.serialPersistentFields is not used\n" + "----------\n", null, @@ -285,15 +284,14 @@ public void test014() { this.runNegativeTest( new String[] { "X.java", - "import java.io.ObjectStreamField;\n" + "public class X {\n" + - " private final static ObjectStreamField[] serialPersistentFields = null;\n" + + " private static final long serialPersistentFields = 1L;\n" + "}" }, "----------\n" + - "1. ERROR in X.java (at line 3)\n" + - " private final static ObjectStreamField[] serialPersistentFields = null;\n" + - " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "1. ERROR in X.java (at line 2)\n" + + " private static final long serialPersistentFields = 1L;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + "The value of the field X.serialPersistentFields is not used\n" + "----------\n", null, diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StackMapAttributeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StackMapAttributeTest.java index 0c08ac5a63..c56f34a830 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StackMapAttributeTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StackMapAttributeTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 IBM Corporation and others. + * Copyright (c) 2006, 2011 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 @@ -34,7 +34,7 @@ public class StackMapAttributeTest extends AbstractRegressionTest { static { // TESTS_PREFIX = "testBug95521"; // TESTS_NAMES = new String[] { "testBug83127a" }; -// TESTS_NUMBERS = new int[] { 47 }; +// TESTS_NUMBERS = new int[] { 53 }; // TESTS_RANGE = new int[] { 23 -1,}; } public static Test suite() { @@ -2285,42 +2285,42 @@ public class StackMapAttributeTest extends AbstractRegressionTest { this.runConformTest( new String[] { "X.java", - "import java.io.StringReader;\r\n" + - "\r\n" + - "public class X {\r\n" + - " public void loadVariablesAndContainers() {\r\n" + - " // backward compatibility, consider persistent property \r\n" + - " String qName = \"1\";\r\n" + - " String xmlString = \"2\";\r\n" + - " \r\n" + - " try {\r\n" + - " if (xmlString != null){\r\n" + - " StringReader reader = new StringReader(xmlString);\r\n" + - " Object o;\r\n" + - " try {\r\n" + - " StringBuffer buffer = null;\r\n" + - " o = new Object();\r\n" + - " } catch(RuntimeException e) {\r\n" + - " return;\r\n" + - " } catch(Exception e){\r\n" + - " return;\r\n" + - " } finally {\r\n" + - " reader.close();\r\n" + - " }\r\n" + - " System.out.println(reader);\r\n" + - " }\r\n" + - " } catch(Exception e){\r\n" + - " // problem loading xml file: nothing we can do\r\n" + - " } finally {\r\n" + - " if (xmlString != null){\r\n" + - " System.out.println(xmlString);\r\n" + - " }\r\n" + - " }\r\n" + - " }\r\n" + - "\r\n" + - " public static void main(String[] args) {\r\n" + + "import java.io.StringReader;\n" + + "\n" + + "public class X {\n" + + " public void loadVariablesAndContainers() {\n" + + " // backward compatibility, consider persistent property \n" + + " String qName = \"1\";\n" + + " String xmlString = \"2\";\n" + + " \n" + + " try {\n" + + " if (xmlString != null){\n" + + " StringReader reader = new StringReader(xmlString);\n" + + " Object o;\n" + + " try {\n" + + " StringBuffer buffer = null;\n" + + " o = new Object();\n" + + " } catch(RuntimeException e) {\n" + + " return;\n" + + " } catch(Exception e){\n" + + " return;\n" + + " } finally {\n" + + " reader.close();\n" + + " }\n" + + " System.out.println(reader);\n" + + " }\n" + + " } catch(Exception e){\n" + + " // problem loading xml file: nothing we can do\n" + + " } finally {\n" + + " if (xmlString != null){\n" + + " System.out.println(xmlString);\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + " System.out.println(\"SUCCESS\");\n" + - " }\r\n" + + " }\n" + "}" }, "SUCCESS"); @@ -6492,24 +6492,24 @@ public class StackMapAttributeTest extends AbstractRegressionTest { this.runNegativeTest( new String[] { "X.java", - "public class X {\r\n" + - " class E1 extends RuntimeException {\r\n" + - " private static final long serialVersionUID = 1L;\r\n" + - " }\r\n" + - " static Object bar() {\r\n" + - " return new Object() {\r\n" + - " public void foo() {\r\n" + - " if (condition())\r\n" + - " throw new E1();\r\n" + - " }\r\n" + - " };\r\n" + - " }\r\n" + - " static boolean condition() {\r\n" + - " return false;\r\n" + - " }\r\n" + - " public static void main(String[] args) {\r\n" + - " }\r\n" + - "}\r\n" + + "public class X {\n" + + " class E1 extends RuntimeException {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " static Object bar() {\n" + + " return new Object() {\n" + + " public void foo() {\n" + + " if (condition())\n" + + " throw new E1();\n" + + " }\n" + + " };\n" + + " }\n" + + " static boolean condition() {\n" + + " return false;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n" + "", }, "----------\n" + @@ -6548,4 +6548,234 @@ public class StackMapAttributeTest extends AbstractRegressionTest { "No enclosing instance of the type X is accessible in scope\n" + "----------\n"); } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=351653 + public void test048() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] p) {\n" + + " int i;\n" + + " try {\n" + + " if (p == null || p == null)\n" + + " return;\n" + + " i = 0;\n" + + " } finally {\n" + + " i = 0;\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=351653 + public void test049() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import java.io.InputStream;\n" + + "\n" + + "public class X implements Runnable {\n" + + "\n" + + " private boolean contentEquals(final String src, final String tar)\n" + + " throws IOException {\n" + + " if (src == null && tar == null) {\n" + + " return true;\n" + + " }\n" + + " if (!isFile(src) || !isFile(tar))\n" + + " throw new IOException(\"cannot compare non-files\");\n" + + " if (size(src) != size(tar))\n" + + " return false;\n" + + " final byte[] baSrc = new byte[8192];\n" + + " final byte[] baTar = new byte[baSrc.length];\n" + + " int lrSrc;\n" + + " int lrTar;\n" + + " InputStream isSrc = null;\n" + + " InputStream isTar = null;\n" + + " try {\n" + + " isSrc = newInputStream(src);\n" + + " if (isSrc == null)\n" + + " return false;\n" + + " isTar = newInputStream(tar);\n" + + " if (isTar == null)\n" + + " return false;\n" + + " do {\n" + + " lrSrc = isSrc.read(baSrc);\n" + + " lrTar = isTar.read(baTar);\n" + + " if (lrSrc != lrTar)\n" + + " return false;\n" + + " for (int i = 0; i < lrSrc; i++)\n" + + " if (baSrc[i] != baTar[i])\n" + + " return false;\n" + + " } while ((lrSrc >= 0) && (lrSrc == lrTar));\n" + + " } finally {\n" + + " try {\n" + + " close(isSrc);\n" + + " } finally {\n" + + " close(isTar);\n" + + " }\n" + + " }\n" + + " return true;\n" + + " }\n" + + " private void close(final InputStream isSrc) {\n" + + " }\n" + + " private boolean isFile(final String src) {\n" + + " return false;\n" + + " }\n" + + " public void run() {\n" + + " try {\n" + + " System.out.println(contentEquals(null, null));\n" + + " } catch (final IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " static InputStream newInputStream(String path) {\n" + + " return null;\n" + + " }\n" + + " static int size(String path) {\n" + + " return 0;\n" + + " }\n" + + " public static void main(final String[] args) {\n" + + " new X().run();\n" + + " }\n" + + "}" + }, + "true"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=352145 + public void test050() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileFilter;\n" + + "import java.io.FileNotFoundException;\n" + + "import java.io.IOException;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static final List<File> copyDir(List<File> lf,\n" + + " final boolean overwrite, final boolean recursive,\n" + + " final boolean returnSrc, final File src, final File tar,\n" + + " final FileFilter filter) throws IOException {\n" + + " if (!src.isDirectory())\n" + + " throw new FileNotFoundException(\"not a directory: \" + src);\n" + + " if (!tar.isDirectory())\n" + + " throw new FileNotFoundException(\"not a directory: \" + tar);\n" + + " final File[] fa = src.listFiles();\n" + + " if (fa == null)\n" + + " throw new FileNotFoundException(\"directory not accessible: \" + src);\n" + + " if (lf == null)\n" + + " lf = new ArrayList<File>(fa.length);\n" + + " for (final File f : fa) {\n" + + " final File right = new File(tar, f.getName());\n" + + " if (f.isDirectory()) {\n" + + " if (recursive && filter.accept(f)) {\n" + + " if (!right.exists())\n" + + " right.mkdir();\n" + + " copyDir(lf, overwrite, recursive, returnSrc, f, right,\n" + + " filter);\n" + + " }\n" + + " } else {\n" + + " if (overwrite || (!right.exists() && filter.accept(f))) {\n" + + " lf.add(returnSrc ? f : right);\n" + + " }\n" + + " }\n" + + " }\n" + + " return lf;\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "\n" + + "}" + }, + "SUCCESS"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=352145 + public void test051() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.IOException;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static final List<File> copyDir(int j, List<File> lf,\n" + + " final boolean returnSrc, final File[] fa) throws IOException {\n" + + " if (lf == null)\n" + + " lf = null;\n" + + " for (int i = 0, max = fa.length; i < max; i++) {\n" + + " final File f = fa[i];\n" + + " final File right = new File(f.getName());\n" + + " if (f.isDirectory()) {\n" + + " } else {\n" + + " lf.add(returnSrc ? f : right);\n" + + " }\n" + + " }\n" + + " return lf;\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "\n" + + "}" + }, + "SUCCESS"); + } + public void test052() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X(int i) {}\n" + + " void foo() {}\n" + + " public static void main(String[] args) {\n" + + " new X(args.length == 2 ? 1 : 2).foo();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + // 352665 + public void test053() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.IGNORE); + customOptions.put(JavaCore.COMPILER_PB_SYNTHETIC_ACCESS_EMULATION, JavaCore.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static {\n" + + " for(int i = 0; i < 10; i++){\n" + + " A a = new A();\n" + + " a.foo();\n" + + " }\n" + + " }\n" + + " private class A {\n" + + " private A() {\n" + + " }\n" + + " void foo() {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " A a = new A();\n" + + " ^^^^^^^\n" + + "No enclosing instance of type X is accessible. Must qualify the allocation with an enclosing instance of type X (e.g. x.new A() where x is an instance of X).\n" + + "----------\n", + null, + true, + customOptions); + } } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java index 4087f9d222..fdc89a03bf 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2011 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 @@ -25,6 +25,9 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; public class SwitchTest extends AbstractRegressionTest { + + private static final long JDKLevelSupportingStringSwitch = ClassFileConstants.JDK1_7; + static { // TESTS_NUMBERS = new int[] { 22 }; } @@ -222,6 +225,50 @@ public void test009() { "SUCCESS"); } public void test010() { + String newMessage = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " switch(this){\n" + + " ^^^^\n" + + "Cannot switch on a value of type X. Only convertible int values, strings or enum constants are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " switch(x){\n" + + " ^\n" + + "x cannot be resolved to a variable\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + String oldMessage = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " switch(this){\n" + + " ^^^^\n" + + "Cannot switch on a value of type X. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " switch(x){\n" + + " ^\n" + + "x cannot be resolved to a variable\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; this.runNegativeTest(new String[] { "X.java", "public class X {\n" + @@ -241,27 +288,8 @@ public void test010() { " } \n" + "}\n", }, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " switch(this){\n" + - " ^^^^\n" + - "Cannot switch on a value of type X. Only convertible int values or enum constants are permitted\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n" + - "3. ERROR in X.java (at line 11)\n" + - " switch(x){\n" + - " ^\n" + - "x cannot be resolved to a variable\n" + - "----------\n" + - "4. ERROR in X.java (at line 13)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); + this.complianceLevel >= JDKLevelSupportingStringSwitch ? newMessage : oldMessage); + } public void test011() { this.runConformTest(new String[] { @@ -829,6 +857,1178 @@ public void test023() { }, "SUCCESS"); } + +// JDK7: Strings in Switch. +public void testStringSwitchAtJDK6() { + String newMessage = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " default: return args;\n" + + " ^^^^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"; + String oldMessage = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " switch(args[0]) {\n" + + " ^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " default: return args;\n" + + " ^^^^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " switch(args[0]) {\n" + + " default: return args;\n" + + " }\n" + + " }\n" + + "}\n", + }, + this.complianceLevel >= JDKLevelSupportingStringSwitch ? newMessage : oldMessage); +} + +//JDK7: Strings in Switch. +public void testCaseTypeMismatch() { + String newMessage = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case 123: break;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " case (byte) 1: break;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from byte to String\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " case (char) 2: break;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from char to String\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " case (short)3: break;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from short to String\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " case (int) 4: break;\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " case (long) 5: break;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from long to String\n" + + "----------\n" + + "7. ERROR in X.java (at line 10)\n" + + " case (float) 6: break;\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from float to String\n" + + "----------\n" + + "8. ERROR in X.java (at line 11)\n" + + " case (double) 7: break;\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from double to String\n" + + "----------\n" + + "9. ERROR in X.java (at line 12)\n" + + " case (boolean) 8: break;\n" + + " ^^^^^^^^^^^\n" + + "Cannot cast from int to boolean\n" + + "----------\n" + + "10. ERROR in X.java (at line 12)\n" + + " case (boolean) 8: break;\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from boolean to String\n" + + "----------\n"; + String oldMessage = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " switch(args[0]) {\n" + + " ^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " case (boolean) 8: break;\n" + + " ^^^^^^^^^^^\n" + + "Cannot cast from int to boolean\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " switch(args[0]) {\n" + + " case 123: break;\n" + + " case (byte) 1: break;\n" + + " case (char) 2: break;\n" + + " case (short)3: break;\n" + + " case (int) 4: break;\n" + + " case (long) 5: break;\n" + + " case (float) 6: break;\n" + + " case (double) 7: break;\n" + + " case (boolean) 8: break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + this.complianceLevel >= JDKLevelSupportingStringSwitch ? newMessage : oldMessage); +} +// JDK7: Strings in Switch. +public void testCaseTypeMismatch2() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + String newMessage = + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case Days.Sunday: break;\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Days to String\n" + + "----------\n"; + String oldMessage = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " switch (\"Sunday\") {\n" + + " ^^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "enum Days { Sunday, Monday, Tuesday, Wednesday, Thuresday, Friday, Satuday };\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String argv[]) {\n" + + " switch (\"Sunday\") {\n" + + " case Days.Sunday: break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + this.complianceLevel >= JDKLevelSupportingStringSwitch ? newMessage : oldMessage); +} +// JDK7: Strings in Switch. +public void testCaseTypeMismatch3() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + String newMessage = + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case \"0\": break;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from String to int\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " case \"Sunday\": break;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from String to Days\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " case \"0\": break;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from String to Integer\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "enum Days { Sunday, Monday, Tuesday, Wednesday, Thuresday, Friday, Satuday };\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String argv[]) {\n" + + " switch (argv.length) {\n" + + " case \"0\": break;\n" + + " }\n" + + " switch(Days.Sunday) {\n" + + " case \"Sunday\": break;\n" + + " }\n" + + " switch (new Integer(argv.length)) {\n" + + " case \"0\": break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + newMessage); +} +// JDK7: Strings in Switch. +public void testDuplicateCase() { + String newMessage = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case \"123\": break;\n" + + " ^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " case \"123\": break;\n" + + " ^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " default: return args;\n" + + " ^^^^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"; + + String oldMessage = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " switch(args[0]) {\n" + + " ^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " default: return args;\n" + + " ^^^^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " switch(args[0]) {\n" + + " case \"123\": break;\n" + + " case \"123\": break;\n" + + " default: return args;\n" + + " }\n" + + " }\n" + + "}\n", + }, + this.complianceLevel >= JDKLevelSupportingStringSwitch ? newMessage : oldMessage); +} + +// JDK7: Strings in Switch. +public void testDuplicateCase2() { + String newMessage = + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " case \"123\": break;\n" + + " ^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " case \"123\": break;\n" + + " ^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " case \"1\" + \"2\" + \"3\": break;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " case local: break;\n" + + " ^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " case field: break;\n" + + " ^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "6. ERROR in X.java (at line 15)\n" + + " case ifield: break;\n" + + " ^^^^^^\n" + + "Cannot make a static reference to the non-static field ifield\n" + + "----------\n" + + "7. ERROR in X.java (at line 16)\n" + + " case inffield: break;\n" + + " ^^^^^^^^\n" + + "Cannot make a static reference to the non-static field inffield\n" + + "----------\n" + + "8. ERROR in X.java (at line 19)\n" + + " default: break;\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"; + + String oldMessage = + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " switch(args[0]) {\n" + + " ^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " case ifield: break;\n" + + " ^^^^^^\n" + + "Cannot make a static reference to the non-static field ifield\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " case inffield: break;\n" + + " ^^^^^^^^\n" + + "Cannot make a static reference to the non-static field inffield\n" + + "----------\n" + + "4. ERROR in X.java (at line 19)\n" + + " default: break;\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " static final String field = \"123\";\n" + + " final String ifield = \"123\";\n" + + " String inffield = \"123\";\n" + + " static String nffield = \"123\";\n" + + " public static void main(String [] args, final String argument) {\n" + + " final String local = \"123\";\n" + + " switch(args[0]) {\n" + + " case \"123\": break;\n" + + " case \"\u0031\u0032\u0033\": break;\n" + + " case \"1\" + \"2\" + \"3\": break;\n" + + " default: break;\n" + + " case local: break;\n" + + " case field: break;\n" + + " case ifield: break;\n" + + " case inffield: break;\n" + + " case nffield: break;\n" + + " case argument: break;\n" + + " default: break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + this.complianceLevel >= JDKLevelSupportingStringSwitch ? newMessage : oldMessage); +} +// JDK7: Strings in Switch. +public void testVariableCase() { + String newMessage = + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case local: break;\n" + + " ^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " case argument: break;\n" + + " ^^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " case inffield: break;\n" + + " ^^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " case nffield: break;\n" + + " ^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " case argument: break;\n" + + " ^^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n"; + + String oldMessage = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " switch(args[0]) {\n" + + " ^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " String inffield = \"123\";\n" + + " static String nffield = \"123\";\n" + + " public void main(String [] args, final String argument) {\n" + + " String local = \"123\";\n" + + " switch(args[0]) {\n" + + " case local: break;\n" + + " case argument: break;\n" + + " case inffield: break;\n" + + " case nffield: break;\n" + + " case argument: break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + this.complianceLevel >= JDKLevelSupportingStringSwitch ? newMessage : oldMessage); +} +// JDK7: Strings in Switch. +public void testVariableCaseFinal() { + String newMessage = + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " case argument: break;\n" + + " ^^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " case argument: break;\n" + + " ^^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n"; + + String oldMessage = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " switch(args[0]) {\n" + + " ^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " final String inffield = \"12312\";\n" + + " final static String nffield = \"123123\";\n" + + " public void main(String [] args, final String argument) {\n" + + " final String local = \"1233\";\n" + + " switch(args[0]) {\n" + + " case local: break;\n" + + " case argument: break;\n" + + " case inffield: break;\n" + + " case nffield: break;\n" + + " case argument: break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + this.complianceLevel >= JDKLevelSupportingStringSwitch ? newMessage : oldMessage); +} +//JDK7: Strings in Switch. +public void testNullCase() { + String newMessage = + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case local: break;\n" + + " ^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " case argument: break;\n" + + " ^^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " case inffield: break;\n" + + " ^^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " case nffield: break;\n" + + " ^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " case (String) null: break;\n" + + " ^^^^^^^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n" + + "6. ERROR in X.java (at line 12)\n" + + " case true ? (String) null : (String) null : break;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n" + + "7. WARNING in X.java (at line 12)\n" + + " case true ? (String) null : (String) null : break;\n" + + " ^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"; + + String oldMessage = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " switch(args[0]) {\n" + + " ^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " final String inffield = null;\n" + + " final static String nffield = null;\n" + + " public void main(String [] args, final String argument) {\n" + + " final String local = null;\n" + + " switch(args[0]) {\n" + + " case local: break;\n" + + " case argument: break;\n" + + " case inffield: break;\n" + + " case nffield: break;\n" + + " case (String) null: break;\n" + + " case true ? (String) null : (String) null : break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + this.complianceLevel >= JDKLevelSupportingStringSwitch ? newMessage : oldMessage); +} +// JDK7: Strings in Switch. +public void testDuplicateCase3() { + String newMessage = + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " case \"123\": break;\n" + + " ^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " case \"1\" + \"2\" + \"3\": break;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " case local: break;\n" + + " ^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " case field: break;\n" + + " ^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " case ifield: break;\n" + + " ^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "6. ERROR in X.java (at line 18)\n" + + " default: break;\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"; + + String oldMessage = + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " switch(args[0]) {\n" + + " ^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " default: break;\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " static final String field = \"123\";\n" + + " final String ifield = \"123\";\n" + + " String inffield = \"123\";\n" + + " static String nffield = \"123\";\n" + + " public void main(String [] args, final String argument) {\n" + + " final String local = \"123\";\n" + + " switch(args[0]) {\n" + + " case \"123\": break;\n" + + " case \"1\" + \"2\" + \"3\": break;\n" + + " default: break;\n" + + " case local: break;\n" + + " case field: break;\n" + + " case ifield: break;\n" + + " case inffield: break;\n" + + " case nffield: break;\n" + + " case argument: break;\n" + + " default: break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + this.complianceLevel >= JDKLevelSupportingStringSwitch ? newMessage : oldMessage); +} + +public void testDuplicateHashCode() { + String errorMsg = + "----------\n" + + "1. ERROR in testDuplicateHashCode.java (at line 5)\n" + + " switch (dispatcher) {\n" + + " ^^^^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "testDuplicateHashCode.java", + "public class testDuplicateHashCode {\n" + + " public static void main(String[] argv) {\n" + + " String dispatcher = \"\u0000\";\n" + + " for (int i = 0; i < 100; i++) {\n" + + " switch (dispatcher) {\n" + + " case \"\u0000\":\n" + + " System.out.print(\"1 \");\n" + + " break;\n" + + " case \"\u0000\u0000\":\n" + + " System.out.print(\"2 \");\n" + + " break;\n" + + " case \"\u0000\u0000\u0000\":\n" + + " System.out.print(\"3 \");\n" + + " break;\n" + + " case \"\u0000\u0000\u0000\u0000\":\n" + + " System.out.print(\"4 \");\n" + + " break;\n" + + " case \"\u0000\u0000\u0000\u0000\u0000\":\n" + + " System.out.print(\"5 \");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"Default\");\n" + + " System.exit(0);\n" + + " case \"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\":\n" + + " System.out.print(\"8 \");\n" + + " break;\n" + + " case \"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\":\n" + + " System.out.print(\"7 \");\n" + + " break;\n" + + " case \"\u0000\u0000\u0000\u0000\u0000\u0000\":\n" + + " System.out.print(\"6 \");\n" + + " break;\n" + + " }\n" + + " dispatcher += \"\u0000\";\n" + + " }\n" + + " }\n" + + "}\n", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "1 2 3 4 5 6 7 8 Default"); + } +} +public void testDuplicateHashCode2() { + String errorMsg = + "----------\n" + + "1. ERROR in testDuplicateHashCode.java (at line 5)\n" + + " switch (dispatcher) {\n" + + " ^^^^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "testDuplicateHashCode.java", + "public class testDuplicateHashCode {\n" + + " public static void main(String[] argv) {\n" + + " String dispatcher = \"\u0000\";\n" + + " while(true) {\n" + + " switch (dispatcher) {\n" + + " case \"\u0000\":\n" + + " System.out.print(\"1 \");\n" + + " dispatcher += \"\u0000\u0000\";\n" + + " break;\n" + + " case \"\u0000\u0000\":\n" + + " System.out.print(\"2 \");\n" + + " dispatcher = \"\";\n" + + " break;\n" + + " case \"\u0000\u0000\u0000\":\n" + + " System.out.print(\"3 \");\n" + + " dispatcher += \"\u0000\u0000\";\n" + + " break;\n" + + " case \"\u0000\u0000\u0000\u0000\":\n" + + " System.out.print(\"4 \");\n" + + " dispatcher = \"\u0000\u0000\";\n" + + " break;\n" + + " case \"\u0000\u0000\u0000\u0000\u0000\":\n" + + " System.out.print(\"5 \");\n" + + " dispatcher += \"\u0000\u0000\";\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"Default\");\n" + + " System.exit(0);\n" + + " case \"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\":\n" + + " System.out.print(\"8 \");\n" + + " dispatcher = \"\u0000\u0000\u0000\u0000\u0000\u0000\";\n" + + " break;\n" + + " case \"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\":\n" + + " System.out.print(\"7 \");\n" + + " dispatcher += \"\u0000\";\n" + + " break;\n" + + " case \"\u0000\u0000\u0000\u0000\u0000\u0000\":\n" + + " System.out.print(\"6 \");\n" + + " dispatcher = \"\u0000\u0000\u0000\u0000\";\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "1 3 5 7 8 6 4 2 Default"); + } +} +public void testSwitchOnNull() { + String errorMsg = + "----------\n" + + "1. ERROR in testSwitchOnNull.java (at line 13)\n" + + " switch (s) {\n" + + " ^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "2. ERROR in testSwitchOnNull.java (at line 23)\n" + + " switch ((String) null) {\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "3. ERROR in testSwitchOnNull.java (at line 33)\n" + + " switch (someMethod()) {\n" + + " ^^^^^^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "4. ERROR in testSwitchOnNull.java (at line 40)\n" + + " switch (nullString) {\n" + + " ^^^^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "5. ERROR in testSwitchOnNull.java (at line 47)\n" + + " switch (someMethod()) {\n" + + " ^^^^^^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "testSwitchOnNull.java", + "public class testSwitchOnNull {\n" + + "\n" + + " private static String someMethod() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " static String nullString = null;\n" + + " public static void main(String [] args) {\n" + + "\n" + + " String s = null;\n" + + "\n" + + " try {\n" + + " switch (s) {\n" + + " default: \n" + + " System.out.println(\"OOPS\");\n" + + " break;\n" + + " }\n" + + " System.out.println(\"OOPS\");\n" + + " } catch (NullPointerException e) {\n" + + " System.out.print(\"NPE1\");\n" + + " }\n" + + " try {\n" + + " switch ((String) null) {\n" + + " default: \n" + + " System.out.println(\"OOPS\");\n" + + " break;\n" + + " }\n" + + " System.out.println(\"OOPS\");\n" + + " } catch (NullPointerException e) {\n" + + " System.out.print(\"NPE2\");\n" + + " }\n" + + " try {\n" + + " switch (someMethod()) {\n" + + " }\n" + + " System.out.println(\"OOPS\");\n" + + " } catch (NullPointerException e) {\n" + + " System.out.print(\"NPE3\");\n" + + " }\n" + + " try {\n" + + " switch (nullString) {\n" + + " }\n" + + " System.out.println(\"OOPS\");\n" + + " } catch (NullPointerException e) {\n" + + " System.out.print(\"NPE4\");\n" + + " }\n" + + " try {\n" + + " switch (someMethod()) {\n" + + " default: \n" + + " System.out.println(\"OOPS\");\n" + + " break;\n" + + " }\n" + + " System.out.println(\"OOPS\");\n" + + " } catch (NullPointerException e) {\n" + + " System.out.print(\"NPE5\");\n" + + " }\n" + + " }\n" + + "}\n", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "NPE1NPE2NPE3NPE4NPE5"); + } +} +public void testSideEffect() { + String errorMsg = + "----------\n" + + "1. ERROR in testSideEffect.java (at line 11)\n" + + " switch(dispatcher()) {\n" + + " ^^^^^^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "testSideEffect.java", + "public class testSideEffect {\n" + + " static boolean firstTime = true;\n" + + " private static String dispatcher() {\n" + + " if (!firstTime) {\n" + + " System.out.print(\"OOPS\");\n" + + " }\n" + + " firstTime = false;\n" + + " return \"\u0000\";\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " switch(dispatcher()) {\n" + + " case \"\u0000\u0000\": break;\n" + + " case \"\u0000\u0000\u0000\": break;\n" + + " case \"\u0000\u0000\u0000\u0000\": break;\n" + + " case \"\u0000\u0000\u0000\u0000\u0000\": break;\n" + + " default: System.out.println(\"DONE\");\n" + + " }\n" + + " }\n" + + "}\n", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "DONE"); + } +} +public void testFallThrough() { + String errorMsg = + "----------\n" + + "1. ERROR in testFallThrough.java (at line 11)\n" + + " switch(s = dispatcher()) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "testFallThrough.java", + "public class testFallThrough {\n" + + " static int index = -1;\n" + + " static String string = \"0123456789*\";\n" + + " private static String dispatcher() {\n" + + " index++;\n" + + " return string.substring(index,index + 1);\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " while (true) {\n" + + " String s = null;\n" + + " switch(s = dispatcher()) {\n" + + " case \"2\":\n" + + " case \"0\":\n" + + " case \"4\":\n" + + " case \"8\":\n" + + " case \"6\":\n" + + " System.out.print(s + \"(even) \");\n" + + " break;\n" + + " case \"1\":\n" + + " case \"3\":\n" + + " case \"9\":\n" + + " case \"5\":\n" + + " case \"7\":\n" + + " System.out.print(s + \"(odd) \");\n" + + " break;\n" + + " default: System.out.print(\"DONE\");\n" + + " System.exit(0);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "0(even) 1(odd) 2(even) 3(odd) 4(even) 5(odd) 6(even) 7(odd) 8(even) 9(odd) DONE"); + } +} +public void testFallThrough2() { + String errorMsg = + "----------\n" + + "1. ERROR in testFallThrough.java (at line 11)\n" + + " switch(s = dispatcher()) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "testFallThrough.java", + "public class testFallThrough {\n" + + " static int index = -1;\n" + + " static String string = \"0123456789*\";\n" + + " private static String dispatcher() {\n" + + " index++;\n" + + " return string.substring(index,index + 1);\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " while (true) {\n" + + " String s = null;\n" + + " switch(s = dispatcher()) {\n" + + " case \"4\": System.out.print(s);\n" + + " case \"3\": System.out.print(s);\n" + + " case \"2\": System.out.print(s);\n" + + " case \"1\": System.out.print(s + \" \");\n" + + " case \"0\": break;\n" + + " default: System.out.print(\"DONE\");\n" + + " System.exit(0);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "1 22 333 4444 DONE"); + } +} +public void testMarysLamb() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + + String errorMsg = + "----------\n" + + "1. ERROR in testMarysLamb.java (at line 4)\n" + + " switch(s) {\n" + + " ^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "testMarysLamb.java", + "public class testMarysLamb {\n" + + " public static void main(String [] args) {\n" + + " for (String s : new String [] { \"Mary\", \"Had\", \"A\", \"Little\", \"Lamb\" }) {\n" + + " switch(s) {\n" + + " default: System.out.print(s + \" \");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "Mary Had A Little Lamb"); + } +} +public void testBreakOut() { + String errorMsg = + "----------\n" + + "1. ERROR in testBreakOut.java (at line 5)\n" + + " switch(s) {\n" + + " ^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "testBreakOut.java", + "public class testBreakOut {\n" + + " public static void main(String [] args) {\n" + + " junk: while (true) {\n" + + " String s = \"\";\n" + + " switch(s) {\n" + + " case \"7\":\n" + + " System.out.print(s + \"(odd) \");\n" + + " break;\n" + + " default: System.out.print(\"DONE\");\n" + + " System.exit(0);\n" + + " break junk;\n" + + " }\n" + + " }\n" + + " System.out.println(\"Broken\");\n" + + " }\n" + + "}\n", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "DONE"); + } +} +public void testMultipleSwitches() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + String errorMsg = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " switch (s) {\n" + + " ^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 35)\n" + + " switch (s) {\n" + + " ^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "3. ERROR in X.java (at line 51)\n" + + " switch (s) {\n" + + " ^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " \n" + + " for (String s: new String [] { \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"DONE\"}) {\n" + + " switch (s) {\n" + + " case \"Sunday\" : \n" + + " System.out.print(\"Sunday\");\n" + + " break;\n" + + " case \"Monday\" :\n" + + " System.out.print(\"Monday\");\n" + + " break;\n" + + " case \"Tuesday\" :\n" + + " System.out.print(\"Tuesday\");\n" + + " break;\n" + + " case \"Wednesday\":\n" + + " System.out.print(\"Wednesday\");\n" + + " break;\n" + + " case \"Thursday\":\n" + + " System.out.print(\"Thursday\");\n" + + " break;\n" + + " case \"Friday\":\n" + + " System.out.print(\"Friday\");\n" + + " break;\n" + + " case \"Saturday\":\n" + + " System.out.print(\"Saturday\");\n" + + " break;\n" + + " default:\n" + + " System.out.print(\" ---- \");\n" + + " break;\n" + + " }\n" + + " }\n" + + " \n" + + " for (String s: new String [] { \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"DONE\"}) {\n" + + " switch (s) {\n" + + " case \"Sunday\" : \n" + + " case \"Monday\" :\n" + + " case \"Tuesday\" :\n" + + " case \"Wednesday\":\n" + + " case \"Thursday\":\n" + + " case \"Friday\":\n" + + " case \"Saturday\":\n" + + " System.out.print(s);\n" + + " break;\n" + + " default:\n" + + " System.out.print(\" ---- \");\n" + + " break;\n" + + " } \n" + + " }\n" + + " for (String s: new String [] { \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"DONE\"}) {\n" + + " switch (s) {\n" + + " case \"Saturday\":\n" + + " case \"Sunday\" : \n" + + " System.out.print(\"Holiday\");\n" + + " break;\n" + + " case \"Monday\" :\n" + + " case \"Tuesday\" :\n" + + " case \"Wednesday\":\n" + + " case \"Thursday\":\n" + + " case \"Friday\":\n" + + " System.out.print(\"Workday\");\n" + + " break;\n" + + " default:\n" + + " System.out.print(\" DONE\");\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + "}\n", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "SundayMondayTuesdayWednesdayThursdayFridaySaturday ---- SundayMondayTuesdayWednesdayThursdayFridaySaturday ---- HolidayWorkdayWorkdayWorkdayWorkdayWorkdayHoliday DONE"); + } +} +public void testNestedSwitches() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + String errorMsg = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " switch (s) {\n" + + " ^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " switch (s) {\n" + + " ^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " switch (s) {\n" + + " ^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " for (String s: new String [] { \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"DONE\"}) {\n" + + " switch (s) {\n" + + " case \"Saturday\":\n" + + " case \"Sunday\" : \n" + + " switch (s) {\n" + + " case \"Saturday\" : System.out.println (\"Saturday is a holiday\"); break;\n" + + " case \"Sunday\" : System.out.println (\"Sunday is a holiday\"); break;\n" + + " default: System.out.println(\"Broken\");\n" + + " }\n" + + " break;\n" + + " case \"Monday\" :\n" + + " case \"Tuesday\" :\n" + + " case \"Wednesday\":\n" + + " case \"Thursday\":\n" + + " case \"Friday\":\n" + + " switch (s) {\n" + + " case \"Monday\" : System.out.println (\"Monday is a workday\"); break;\n" + + " case \"Tuesday\" : System.out.println (\"Tuesday is a workday\"); break;\n" + + " case \"Wednesday\": System.out.println (\"Wednesday is a workday\"); break;\n" + + " case \"Thursday\": System.out.println (\"Thursday is a workday\"); break;\n" + + " case \"Friday\":System.out.println (\"Friday is a workday\"); break;\n" + + " default: System.out.println(\"Broken\");\n" + + " }\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"DONE\");\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "Sunday is a holiday\n" + + "Monday is a workday\n" + + "Tuesday is a workday\n" + + "Wednesday is a workday\n" + + "Thursday is a workday\n" + + "Friday is a workday\n" + + "Saturday is a holiday\n" + + "DONE"); + } +} public static Class testClass() { return SwitchTest.class; } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java index ac7a0244ab..28a772e07e 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java @@ -164,6 +164,13 @@ public static Test suite() { tests_1_7.addAll(since_1_5); tests_1_7.addAll(since_1_6); tests_1_7.add(AssignmentTest_1_7.class); + tests_1_7.add(BinaryLiteralTest.class); + tests_1_7.add(UnderscoresInLiteralsTest.class); + tests_1_7.add(TryStatement17Test.class); + tests_1_7.add(TryWithResourcesStatementTest.class); + tests_1_7.add(GenericsRegressionTest_1_7.class); + tests_1_7.add(PolymorphicSignatureTest.class); + tests_1_7.add(Compliance_1_7.class); // Reset forgotten subsets tests TestCase.TESTS_PREFIX = null; TestCase.TESTS_NAMES = null; diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java new file mode 100644 index 0000000000..ba8feb82d2 --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java @@ -0,0 +1,1173 @@ +/******************************************************************************* + * Copyright (c) 2003, 2011 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 + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; +public class TryStatement17Test extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "test061" }; +// TESTS_NUMBERS = new int[] { 40, 41, 43, 45, 63, 64 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public TryStatement17Test(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_7); +} +public void test001() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println();\n" + + " Reader r = new FileReader(args[0]);\n" + + " r.read();\n" + + " } catch(IOException | FileNotFoundException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " } catch(IOException | FileNotFoundException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The exception FileNotFoundException is already caught by the alternative IOException\n" + + "----------\n"); +} +public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println();\n" + + " Reader r = new FileReader(args[0]);\n" + + " r.read();\n" + + " } catch(FileNotFoundException | FileNotFoundException | IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " } catch(FileNotFoundException | FileNotFoundException | IOException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The exception FileNotFoundException is already caught by the alternative FileNotFoundException\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " } catch(FileNotFoundException | FileNotFoundException | IOException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The exception FileNotFoundException is already caught by the alternative IOException\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " } catch(FileNotFoundException | FileNotFoundException | IOException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The exception FileNotFoundException is already caught by the alternative IOException\n" + + "----------\n"); +} +public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println();\n" + + " Reader r = new FileReader(args[0]);\n" + + " r.read();\n" + + " } catch(FileNotFoundException e) {" + + " e.printStackTrace();\n" + + " } catch(FileNotFoundException | IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " } catch(FileNotFoundException | IOException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The exception FileNotFoundException is already caught by the alternative IOException\n" + + "----------\n"); +} +public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println();\n" + + " Reader r = new FileReader(args[0]);\n" + + " r.read();\n" + + " } catch(RuntimeException | Exception e) {" + + " e.printStackTrace();\n" + + " } catch(FileNotFoundException | IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " } catch(RuntimeException | Exception e) { e.printStackTrace();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The exception RuntimeException is already caught by the alternative Exception\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " } catch(FileNotFoundException | IOException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The exception FileNotFoundException is already caught by the alternative IOException\n" + + "----------\n"); +} +public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println();\n" + + " Reader r = new FileReader(\"Zork\");\n" + + " r.read();\n" + + " } catch(NumberFormatException | RuntimeException e) {\n" + + " e.printStackTrace();\n" + + " } catch(FileNotFoundException | IOException e) {\n" + + " // ignore\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " } catch(NumberFormatException | RuntimeException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The exception NumberFormatException is already caught by the alternative RuntimeException\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " } catch(FileNotFoundException | IOException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The exception FileNotFoundException is already caught by the alternative IOException\n" + + "----------\n"); +} +//Test that lub is not used for checking for checking the exceptions +public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new Foo();\n"+ + " } catch(SonOfFoo | DaughterOfFoo e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n" + + "class Foo extends Exception {}\n"+ + "class SonOfFoo extends Foo {}\n"+ + "class DaughterOfFoo extends Foo {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " throw new Foo();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type Foo\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +public void test007() { + this.runConformTest( + new String[] { + "X.java", + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new Foo();\n"+ + " } catch(SonOfFoo | DaughterOfFoo e) {\n" + + " System.out.println(\"Caught lub\");\n" + + " } catch(Foo e) {\n" + + " System.out.println(\"Caught Foo\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class Foo extends Exception {}\n"+ + "class SonOfFoo extends Foo {}\n"+ + "class DaughterOfFoo extends Foo {}\n" + }, + "Caught Foo"); +} +// test that lub is not used for precise rethrow +public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " if (args.length == 0) throw new SonOfFoo();\n"+ + " throw new DaughterOfFoo();\n" + + " } catch(SonOfFoo | DaughterOfFoo e) {\n" + + " try {\n" + + " throw e;\n" + + " } catch(SonOfFoo | DaughterOfFoo e1) {}\n"+ + " }\n" + + " }\n" + + "}\n" + + "class Foo extends Exception {}\n"+ + "class SonOfFoo extends Foo {}\n"+ + "class DaughterOfFoo extends Foo {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new IOException();\n" + + " } catch(IOException | RuntimeException e) {\n" + + " e = new IOException();\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " e = new IOException();\n" + + " ^\n" + + "The parameter e of a multi-catch block cannot be assigned\n" + + "----------\n"); +} +//Test that union type checks are done for a precise throw too +public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new DaughterOfFoo();\n"+ + " } catch(SonOfFoo | DaughterOfFoo e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n" + + "class Foo extends Exception {}\n"+ + "class SonOfFoo extends Foo {}\n"+ + "class DaughterOfFoo extends Foo {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " } catch(SonOfFoo | DaughterOfFoo e) {\n" + + " ^^^^^^^^\n" + + "Unreachable catch block for SonOfFoo. This exception is never thrown from the try statement body\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// Test that a rethrow is precisely computed +public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new DaughterOfFoo();\n"+ + " } catch(Foo e) {\n" + + " try {\n" + + " throw e;\n" + + " } catch (SonOfFoo e1) {\n" + + " e1.printStackTrace();\n" + + " } catch (Foo e1) {}\n" + + " }\n" + + " }\n" + + "}\n"+ + "class Foo extends Exception {}\n"+ + "class SonOfFoo extends Foo {}\n"+ + "class DaughterOfFoo extends Foo {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " } catch (SonOfFoo e1) {\n" + + " ^^^^^^^^\n" + + "Unreachable catch block for SonOfFoo. This exception is never thrown from the try statement body\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 16)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +//Test that a rethrow is precisely computed +public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new DaughterOfFoo();\n"+ + " } catch(Foo e) {\n" + + " try {\n" + + " throw e;\n" + + " } catch (SonOfFoo e1) {\n" + + " e1.printStackTrace();\n" + + " } catch (Foo e1) {}\n" + + " finally {" + + " System.out.println(\"\");}\n" + + " }\n" + + " }\n" + + "}\n"+ + "class Foo extends Exception {}\n"+ + "class SonOfFoo extends Foo {}\n"+ + "class DaughterOfFoo extends Foo {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " } catch (SonOfFoo e1) {\n" + + " ^^^^^^^^\n" + + "Unreachable catch block for SonOfFoo. This exception is never thrown from the try statement body\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 16)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 17)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// Test that if the rethrow argument is modified (not effectively final), then it is not precisely +// computed +public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new DaughterOfFoo();\n"+ + " } catch(Foo e) {\n" + + " try {\n" + + " e = new Foo();\n" + + " throw e;\n" + + " } catch (SonOfFoo e1) {\n" + + " e1.printStackTrace();\n" + + " } catch (Foo e1) {}\n"+ + " }\n" + + " }\n" + + "}\n"+ + "class Foo extends Exception {}\n"+ + "class SonOfFoo extends Foo {}\n"+ + "class DaughterOfFoo extends Foo {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 15)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 17)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} + +// Test that if the rethrow argument is modified in a different flow (not effectively final), then also precise throw +// should not be computed +public void test014() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new DaughterOfFoo();\n"+ + " } catch(Foo e) {\n" + + " try {\n" + + " boolean DEBUG = true;\n" + + " if (DEBUG) {\n" + + " throw e;\n"+ + " }" + + " e = new Foo();\n" + + " e.printStackTrace();\n"+ + " } catch (SonOfFoo e1) {\n" + + " e1.printStackTrace();\n" + + " } catch (Foo e1) {}\n"+ + " }\n" + + " }\n" + + "}\n"+ + "class Foo extends Exception {}\n"+ + "class SonOfFoo extends Foo {}\n"+ + "class DaughterOfFoo extends Foo {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 18)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 19)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 20)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} + +// test015 moved into org.eclipse.jdt.core.tests.compiler.regression.TryStatementTest.test070() + +// Test precise rethrow works good even in nested try catch block +public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new DaughterOfFoo();\n"+ + " } catch(Foo e) {\n" + + " try {\n" + + " throw new Foo();\n" + + " } catch (Foo e1) {\n" + + " try {\n" + + " throw e;\n" + + " } catch (SonOfFoo e2) {\n" + + " e1.printStackTrace();\n" + + " } catch (Foo e3) {}\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"+ + "class Foo extends Exception {}\n"+ + "class SonOfFoo extends Foo {}\n"+ + "class DaughterOfFoo extends Foo {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " } catch (SonOfFoo e2) {\n" + + " ^^^^^^^^\n" + + "Unreachable catch block for SonOfFoo. This exception is never thrown from the try statement body\n" + + "----------\n" + + "2. WARNING in X.java (at line 18)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 19)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 20)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// Test lub computation. +public void test017() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " doSomething(false);\n" + + " }\n" + + " public static void doSomething (boolean bool) {\n" + + " try {\n" + + " if (bool)\n" + + " throw new GrandSonOfFoo();\n" + + " else \n" + + " throw new GrandDaughterOfFoo();\n" + + " } catch(SonOfFoo | DaughterOfFoo e) {\n" + + " SonOfFoo s = e;\n" + + " e.callableOnBothGenders();\n" + + " e.callableOnlyOnMales();\n" + + " e.callableOnlyOnFemales();\n" + + " }\n" + + " }\n" + + "}\n" + + "class Foo extends Exception {\n" + + " void callableOnBothGenders () {\n" + + " }\n" + + "}\n" + + "class SonOfFoo extends Foo {\n" + + " void callableOnlyOnMales() {\n" + + " }\n" + + "}\n" + + "class GrandSonOfFoo extends SonOfFoo {}\n" + + "class DaughterOfFoo extends Foo {\n" + + " void callableOnlyOnFemales() {\n" + + " }\n" + + "}\n" + + "class GrandDaughterOfFoo extends DaughterOfFoo {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " SonOfFoo s = e;\n" + + " ^\n" + + "Type mismatch: cannot convert from Foo to SonOfFoo\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " e.callableOnlyOnMales();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The method callableOnlyOnMales() is undefined for the type Foo\n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " e.callableOnlyOnFemales();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The method callableOnlyOnFemales() is undefined for the type Foo\n" + + "----------\n" + + "4. WARNING in X.java (at line 19)\n" + + " class Foo extends Exception {\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "5. WARNING in X.java (at line 23)\n" + + " class SonOfFoo extends Foo {\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "6. WARNING in X.java (at line 27)\n" + + " class GrandSonOfFoo extends SonOfFoo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class GrandSonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "7. WARNING in X.java (at line 28)\n" + + " class DaughterOfFoo extends Foo {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "8. WARNING in X.java (at line 32)\n" + + " class GrandDaughterOfFoo extends DaughterOfFoo {}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The serializable class GrandDaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// Test explicit final modifiers +public void test018() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(boolean bool) throws Foo {\n" + + " try {\n" + + " if (bool) \n" + + " throw new DaughterOfFoo();\n" + + " else\n" + + " throw new SonOfFoo();\n" + + " } catch (final SonOfFoo | DaughterOfFoo e){\n" + + " throw e;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " foo(true);\n" + + " } catch(Foo e) {} \n" + + " }\n" + + "}\n" + + "class Foo extends Exception {}\n" + + "class SonOfFoo extends Foo {}\n" + + "class DaughterOfFoo extends Foo {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " throw new SonOfFoo();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n" + + "2. WARNING in X.java (at line 18)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 19)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 20)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// Test explicit final modifiers +public void test019() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(boolean bool) throws Foo {\n" + + " try {\n" + + " if (bool) \n" + + " throw new DaughterOfFoo();\n" + + " else\n" + + " throw new SonOfFoo();\n" + + " } catch (final SonOfFoo | final DaughterOfFoo e){\n" + + " throw e;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " foo(true);\n" + + " } catch(Foo e) {} \n" + + " }\n" + + "}\n" + + "class Foo extends Exception {}\n" + + "class SonOfFoo extends Foo {}\n" + + "class DaughterOfFoo extends Foo {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " } catch (final SonOfFoo | final DaughterOfFoo e){\n" + + " ^^^^^\n" + + "Syntax error on token \"final\", delete this token\n" + + "----------\n" + + "2. WARNING in X.java (at line 18)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 19)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 20)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// Test that for unchecked exceptions, we don't do any precise analysis. +public void test020() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " try {\n" + + " } catch (NullPointerException s) {\n" + + " try {\n" + + " throw s;\n" + + " } catch (ArithmeticException e) {\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "All done"); +} +// Test multicatch behavior. +public void test021() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String[] exceptions = { \"NullPointerException\", \"ArithmeticException\",\n" + + " \"ArrayStoreException\", \"ArrayIndexOutOfBoundsException\" };\n" + + "\n" + + " for (String exception : exceptions) {\n" + + " try {\n" + + " switch (exception) {\n" + + " case \"NullPointerException\":\n" + + " throw new NullPointerException();\n" + + " case \"ArithmeticException\":\n" + + " throw new ArithmeticException();\n" + + " case \"ArrayStoreException\":\n" + + " throw new ArrayStoreException();\n" + + " case \"ArrayIndexOutOfBoundsException\":\n" + + " throw new ArrayIndexOutOfBoundsException();\n" + + " }\n" + + " } catch (NullPointerException | ArithmeticException | ArrayStoreException | ArrayIndexOutOfBoundsException e) {\n" + + " System.out.println(e);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "java.lang.NullPointerException\n" + + "java.lang.ArithmeticException\n" + + "java.lang.ArrayStoreException\n" + + "java.lang.ArrayIndexOutOfBoundsException"); +} +public void test022() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T extends Exception> {\n" + + "public void foo(boolean bool) throws Exception {\n" + + " try {\n" + + " if (bool)\n" + + " throw new Exception();\n" + + " else\n" + + " throw new NullPointerException();\n" + + " } catch (T | NullPointerException e) {}\n" + + "}\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " } catch (T | NullPointerException e) {}\n" + + " ^\n" + + "Cannot use the type parameter T in a catch block\n" + + "----------\n" + ); +} +public void test023() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<T> extends Exception {\n" + + "public void foo(boolean bool) throws Exception {\n" + + " try {\n" + + " if (bool)\n" + + " throw new Exception();\n" + + " else\n" + + " throw new NullPointerException();\n" + + " } catch (X<String> | NullPointerException e) {}\n" + + "}\n" + + "}\n"}, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X<T> extends Exception {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X<T> extends Exception {\n" + + " ^^^^^^^^^\n" + + "The generic class X<T> may not subclass java.lang.Throwable\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " } catch (X<String> | NullPointerException e) {}\n" + + " ^\n" + + "Cannot use the parameterized type X<String> either in catch block or throws clause\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340486 +public void test024() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.FileNotFoundException;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " try {\n" + + " if (args.length == 0)\n" + + " throw new FileNotFoundException();\n" + + " throw new IOException();\n" + + " } catch(IOException | FileNotFoundException e) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " } catch(IOException | FileNotFoundException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The exception FileNotFoundException is already caught by the alternative IOException\n" + + "----------\n"); +} +public void test024a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.FileNotFoundException;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " try {\n" + + " if (args.length == 0)\n" + + " throw new FileNotFoundException();\n" + + " throw new IOException();\n" + + " } catch(FileNotFoundException | IOException e) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " } catch(FileNotFoundException | IOException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The exception FileNotFoundException is already caught by the alternative IOException\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=344824 +public void test025() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new D();\n" + + " } catch (F e) {\n" + + " try {\n" + + " throw e;\n" + + " } catch (F f) {\n" + + " } catch (RuntimeException | S f) {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + + "class F extends Exception {}\n" + + "class S extends F {}\n" + + "class D extends F {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " } catch (RuntimeException | S f) {\n" + + " ^\n" + + "Unreachable catch block for S. It is already handled by the catch block for F\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " class F extends Exception {}\n" + + " ^\n" + + "The serializable class F does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " class S extends F {}\n" + + " ^\n" + + "The serializable class S does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 16)\n" + + " class D extends F {}\n" + + " ^\n" + + "The serializable class D does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345522 +public void test026() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.EOFException;\n" + + "import java.io.FileNotFoundException;\n" + + "public class X {\n" + + " X() { \n" + + " try {\n" + + " zoo();\n" + + " } catch (EOFException ea) {\n" + + " } catch (FileNotFoundException eb) {\n" + + " } catch (Exception ec) {\n" + + " throw ec;\n" + + " }\n" + + " }\n" + + " void zoo() throws FileNotFoundException, EOFException {\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345522 +public void test026a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.EOFException;\n" + + "import java.io.FileNotFoundException;\n" + + "public class X {\n" + + " X() { \n" + + " try {\n" + + " zoo();\n" + + " throw new Exception();\n" + + " } catch (EOFException ea) {\n" + + " } catch (FileNotFoundException eb) {\n" + + " } catch (Exception ec) {\n" + + " throw ec;\n" + + " }\n" + + " }\n" + + " void zoo() throws FileNotFoundException, EOFException {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " throw ec;\n" + + " ^^^^^^^^^\n" + + "Unhandled exception type Exception\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=345579 +public void test027() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " X() throws Exception {\n"+ + " try {\n"+ + " throw (Throwable) new Exception();\n"+ + " } catch (Exception e) {\n"+ + " throw e;\n"+ + " } catch (Throwable e) {\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=350361 +public void test028() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public void foo () {\n"+ + " try {\n"+ + " throw new Exception(); \n"+ + " } catch (Exception e) {\n"+ + " if (e instanceof RuntimeException) \n" + + " throw (RuntimeException) e; \n"+ + " } \n"+ + " }\n"+ + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=350579 +public void test029() { // with finally + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String[] args) {\n" + + " try (X x = new X();) {\n" + + " } catch (Exception x) {\n" + + " } catch (Throwable y) {\n" + + " } \n" + + " finally {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " }\n" + + " public void close() {\n" + + " }\n" + + "}\n" + }, + "Done"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=350579 +public void test030() { // no finally + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String[] args) {\n" + + " try (X x = new X();) {\n" + + " } catch (Exception x) {\n" + + " } catch (Throwable y) {\n" + + " } \n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " public void close() {\n" + + " }\n" + + "}\n" + }, + "Done"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=350579 +public void test031() { // with finally + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) throws XXException, YYException, ZZException {\n" + + " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + + " } catch (XException x) {\n" + + " } catch (YException y) {\n" + + " } catch (ZException z) {\n" + + " } finally {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " }\n" + + " public X() throws XException {\n" + + " throw new XException();\n" + + " }\n" + + " public void close() throws XXException {\n" + + " throw new XXException();\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() throws YException {\n" + + " throw new YException();\n" + + " }\n" + + " public void close() throws YYException {\n" + + " throw new YYException();\n" + + " }\n" + + "}\n" + + "class Z implements AutoCloseable {\n" + + " public Z() throws ZException {\n" + + " throw new ZException();\n" + + " }\n" + + " public void close() throws ZZException {\n" + + " throw new ZZException();\n" + + " }\n" + + "}\n" + + "class XException extends Exception {}\n" + + "class XXException extends Exception {}\n" + + "class YException extends Exception {}\n" + + "class YYException extends Exception {}\n" + + "class ZException extends Exception {}\n" + + "class ZZException extends Exception {}\n" + }, + "Done"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=350579 +public void test032() { // no finally + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) throws XXException, YYException, ZZException {\n" + + " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + + " } catch (XException x) {\n" + + " } catch (YException y) {\n" + + " } catch (ZException z) {\n" + + " }\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " public X() throws XException {\n" + + " throw new XException();\n" + + " }\n" + + " public void close() throws XXException {\n" + + " throw new XXException();\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() throws YException {\n" + + " throw new YException();\n" + + " }\n" + + " public void close() throws YYException {\n" + + " throw new YYException();\n" + + " }\n" + + "}\n" + + "class Z implements AutoCloseable {\n" + + " public Z() throws ZException {\n" + + " throw new ZException();\n" + + " }\n" + + " public void close() throws ZZException {\n" + + " throw new ZZException();\n" + + " }\n" + + "}\n" + + "class XException extends Exception {}\n" + + "class XXException extends Exception {}\n" + + "class YException extends Exception {}\n" + + "class YYException extends Exception {}\n" + + "class ZException extends Exception {}\n" + + "class ZZException extends Exception {}\n" + }, + "Done"); +} +public static Class testClass() { + return TryStatement17Test.class; +} +} diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java index 036fabf923..78b5aa403e 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2008 IBM Corporation and others. + * Copyright (c) 2003, 2011 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 @@ -24,7 +24,7 @@ public class TryStatementTest extends AbstractRegressionTest { static { // TESTS_NAMES = new String[] { "test000" }; -// TESTS_NUMBERS = new int[] { 40, 41, 43, 45, 63, 64 }; +// TESTS_NUMBERS = new int[] { 74, 75 }; // TESTS_RANGE = new int[] { 11, -1 }; } public TryStatementTest(String name) { @@ -5221,19 +5221,19 @@ public void test058() throws Exception { this.runConformTest( new String[] { "X.java", - "public class X {\r\n" + - " public static void main(String args[]) {\r\n" + - " try {\r\n" + - " try {\r\n" + - " System.out.print(\"SU\");\r\n" + - " } finally {\r\n" + - " System.out.print(\"CC\");\r\n" + - " }\r\n" + - " } finally {\r\n" + - " System.out.println(\"ESS\");\r\n" + - " }\r\n" + - " }\r\n" + - "}\r\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " try {\n" + + " try {\n" + + " System.out.print(\"SU\");\n" + + " } finally {\n" + + " System.out.print(\"CC\");\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"ESS\");\n" + + " }\n" + + " }\n" + + "}\n" + "", }, "SUCCESS"); @@ -5733,6 +5733,237 @@ public void test067() throws Exception { }, "null"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340485 +public void test068() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " doSomething(false);\n" + + " }\n" + + " public static void doSomething (boolean bool) {\n" + + " try {\n" + + " if (bool)\n" + + " throw new GrandSonOfFoo();\n" + + " else \n" + + " throw new GrandDaughterOfFoo();\n" + + " } catch(Foo e) {\n" + + " try { \n" + + " throw e; \n" + + " } catch (SonOfFoo e1) {\n" + + " e1.printStackTrace();\n" + + " } catch (DaughterOfFoo e1) {\n" + + " System.out.println(\"caught a daughter of foo\");\n" + + " } catch (Foo f) {}\n" + + " }\n" + + " }\n" + + "}\n" + + "class Foo extends Exception {}\n" + + "class SonOfFoo extends Foo {}\n" + + "class GrandSonOfFoo extends SonOfFoo {}\n" + + "class DaughterOfFoo extends Foo {}\n" + + "class GrandDaughterOfFoo extends DaughterOfFoo {}\n" + }, + "caught a daughter of foo"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340484 +public void test069() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new DaughterOfFoo();\n" + + " } catch(Foo e) {\n" + + " try { \n" + + " while (true) {\n" + + " throw e; \n" + + " }\n" + + " } catch (SonOfFoo e1) {\n" + + " e1.printStackTrace();\n" + + " } catch (Foo e1) {}\n" + + " }\n" + + " }\n" + + "}\n" + + "class Foo extends Exception {}\n" + + "class SonOfFoo extends Foo {}\n" + + "class DaughterOfFoo extends Foo {}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in X.java (at line 16)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 17)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 18)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " } catch (SonOfFoo e1) {\n" + + " ^^^^^^^^\n" + + "Unreachable catch block for SonOfFoo. This exception is never thrown from the try statement body\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 17)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 18)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// precise throw computation should also take care of throws clause in 1.7. 1.6- should continue to behave as it always has. +public void test070() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo() throws DaughterOfFoo {\n" + + " try {\n" + + " throw new DaughterOfFoo();\n" + + " } catch (Foo e){\n" + + " throw e;\n" + + " foo();\n" + + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n" + + " try {\n" + + " foo();\n"+ + " } catch(Foo e) {}\n" + + " }\n" + + "}\n"+ + "class Foo extends Exception {}\n"+ + "class SonOfFoo extends Foo {}\n"+ + "class DaughterOfFoo extends Foo {}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " throw e;\n" + + " ^^^^^^^^\n" + + "Unhandled exception type Foo\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " foo();\n" + + " ^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. WARNING in X.java (at line 16)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 17)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "5. WARNING in X.java (at line 18)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n": + + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " foo();\n" + + " ^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " class Foo extends Exception {}\n" + + " ^^^\n" + + "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 17)\n" + + " class SonOfFoo extends Foo {}\n" + + " ^^^^^^^^\n" + + "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 18)\n" + + " class DaughterOfFoo extends Foo {}\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348369 +public void test071() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " try {\n" + + " } catch (Exception [][][][][] e [][][][]) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " } catch (Exception [][][][][] e [][][][]) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "No exception of type Exception[][][][][][][][][] can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348369 +public void test072() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " try {\n" + + " } catch (Exception e []) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " } catch (Exception e []) {\n" + + " ^^^^^^^^^^^^^^\n" + + "No exception of type Exception[] can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348369 +public void test073() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " try {\n" + + " } catch (Exception [] e) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " } catch (Exception [] e) {\n" + + " ^^^^^^^^^^^^\n" + + "No exception of type Exception[] can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n"); +} public static Class testClass() { return TryStatementTest.class; } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java new file mode 100644 index 0000000000..98cc062c08 --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java @@ -0,0 +1,3343 @@ +/******************************************************************************* + * Copyright (c) 2011 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 + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; +public class TryWithResourcesStatementTest extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "test053" }; +// TESTS_NUMBERS = new int[] { 50 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public TryWithResourcesStatementTest(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_7); +} +// Test resource type related errors +public void test001() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1(){\n" + + " try (int i = 0) {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (int i = 0) {\n" + + " ^^^\n" + + "The resource type int does not implement java.lang.AutoCloseable\n" + + "----------\n"); +} +// Test resource type related errors +public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1(){\n" + + " try (int[] tab = {}) {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (int[] tab = {}) {\n" + + " ^^^^^\n" + + "The resource type int[] does not implement java.lang.AutoCloseable\n" + + "----------\n"); +} +// Test that resource type could be interface type. +public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements AutoCloseable{\n" + + " public void method1(){\n" + + " try (AutoCloseable a = new X()) {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X implements AutoCloseable{\n" + + " ^\n" + + "The type X must implement the inherited abstract method AutoCloseable.close()\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " try (AutoCloseable a = new X()) {\n" + + " ^\n" + + "Unhandled exception type Exception thrown by automatic close() invocation on a\n" + + "----------\n"); +} +// Type resource type related errors +public void test003a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1(){\n" + + " try (Y y = new Y()) { \n" + + " System.out.println();\n" + + " } catch (Exception e) {\n" + + " } finally {\n" + + " Zork z;\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y implements Managed {\n" + + " public void close () throws Exception {\n" + + " }\n" + + "}\n" + + "interface Managed extends AutoCloseable {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// Scope, visibility related tests. +public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public static void main(String[] args) throws IOException {\n" + + " int i = 0;\n" + + " try (LineNumberReader reader = new LineNumberReader(new BufferedReader(new FileReader(args[0])))) {\n" + + " String s;\n" + + " int i = 0;\n" + + " while ((s = reader.readLine()) != null) {\n" + + " System.out.println(s);\n" + + " i++;\n" + + " }\n" + + " System.out.println(\"\" + i + \" lines\");\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " int i = 0;\n" + + " ^\n" + + "Duplicate local variable i\n" + + "----------\n"); +} +//Scope, visibility related tests. +public void test004a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public static void main(String[] args) throws IOException {\n" + + " try (LineNumberReader r = new LineNumberReader(new BufferedReader(new FileReader(args[0])))) {\n" + + " String s;\n" + + " int r = 0;\n" + + " while ((s = r.readLine()) != null) {\n" + + " System.out.println(s);\n" + + " r++;\n" + + " }\n" + + " System.out.println(\"\" + r + \" lines\");\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " int r = 0;\n" + + " ^\n" + + "Duplicate local variable r\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " while ((s = r.readLine()) != null) {\n" + + " ^^^^^^^^^^^^\n" + + "Cannot invoke readLine() on the primitive type int\n" + + "----------\n"); +} +// check that resources are implicitly final +public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public static void main(String[] args) throws IOException {\n" + + " try (Reader r = new LineNumberReader(new BufferedReader(new FileReader(args[0])))) {\n" + + " r = new FileReader(args[0]);\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " r = new FileReader(args[0]);\n" + + " ^\n" + + "The resource r of a try-with-resources statement cannot be assigned\n" + + "----------\n"); +} +//check that try statement can be empty +public void test006() { + this.runNegativeTest( // cannot be a conform test as this triggers an AIOOB. + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public static void main(String[] args) throws IOException {\n" + + " try (Reader r = new LineNumberReader(new BufferedReader(new FileReader(args[0])))) {\n" + + " } catch(Zork z) {" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " } catch(Zork z) { }\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//check that resources are implicitly final but they can be explicitly final +public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public static void main(String[] args) throws IOException {\n" + + " try (final Reader r = new LineNumberReader(new BufferedReader(new FileReader(args[0])))) {\n" + + " r = new FileReader(args[0]);\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " r = new FileReader(args[0]);\n" + + " ^\n" + + "The resource r of a try-with-resources statement cannot be assigned\n" + + "----------\n"); +} +// resource type tests +public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1(){\n" + + " try (Y [] i = null) {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public void close () {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (Y [] i = null) {\n" + + " ^^^^\n" + + "The resource type Y[] does not implement java.lang.AutoCloseable\n" + + "----------\n"); +} +// Resource Type tests +public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1(){\n" + + " try (Y i [] = null) {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public void close () {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (Y i [] = null) {\n" + + " ^\n" + + "The resource type Y[] does not implement java.lang.AutoCloseable\n" + + "----------\n"); +} +// Scope, visibility tests +public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1(int p){\n" + + " int k;\n" + + " try (Y i = new Y(); Y i = new Y(); Y p = new Y(); Y k = new Y();) {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public void close () {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " try (Y i = new Y(); Y i = new Y(); Y p = new Y(); Y k = new Y();) {\n" + + " ^\n" + + "Duplicate local variable i\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " try (Y i = new Y(); Y i = new Y(); Y p = new Y(); Y k = new Y();) {\n" + + " ^\n" + + "Duplicate local variable p\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " try (Y i = new Y(); Y i = new Y(); Y p = new Y(); Y k = new Y();) {\n" + + " ^\n" + + "Duplicate local variable k\n" + + "----------\n"); +} +// Scope, visibility tests +public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1(){\n" + + " try (Y i = new Y(); Y p = new Y(); Y k = new Y();) {\n" + + " System.out.println();\n" + + " }\n" + + " catch (Exception e) {\n" + + " System.out.println(i);\n" + + " }\n" + + " finally {\n" + + " System.out.println(p);\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public void close () {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(i);\n" + + " ^\n" + + "i cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " System.out.println(p);\n" + + " ^\n" + + "p cannot be resolved to a variable\n" + + "---" + + "-------\n"); +} +// Scope, visibility related tests. +public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1(){\n" + + " try (Y i = new Y(); Y p = new Y(); Y k = new Y();) {\n" + + " try {\n" + + " System.out.println();\n" + + " } catch (Exception i) {\n" + + " }\n" + + " }\n" + + " catch (Exception e) {\n" + + " System.out.println(i);\n" + + " }\n" + + " finally {\n" + + " System.out.println(p);\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public void close () {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " } catch (Exception i) {\n" + + " ^\n" + + "Duplicate parameter i\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " System.out.println(i);\n" + + " ^\n" + + "i cannot be resolved to a variable\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " System.out.println(p);\n" + + " ^\n" + + "p cannot be resolved to a variable\n" + + "----------\n"); +} +// Shadowing behavior tests +public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " try (Y y = new Y(); Y p = new Y()) {\n" + + " X x = new X() {\n" + + " public void foo(int p) {\n" + + " try {\n" + + " System.out.println();\n" + + " } catch (Exception y) {\n" + + " }\n" + + " }\n" + + " };\n" + + " } finally {\n" + + " System.out.println(y);\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class Y implements AutoCloseable {\n" + + " public void close() {\n" + + " System.out.println();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public void foo(int p) {\n" + + " ^\n" + + "The parameter p is hiding another local variable defined in an enclosing type scope\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " } catch (Exception y) {\n" + + " ^\n" + + "The parameter y is hiding another local variable defined in an enclosing type scope\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " System.out.println(y);\n" + + " ^\n" + + "y cannot be resolved to a variable\n" + + "----------\n"); +} +// Test for unhandled exceptions +public void test014() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) { \n" + + " try (Y y = new Y();) {\n" + + " if (y == null) {}\n" + + " Y why = new Y();\n" + + " System.out.println(\"Try block\");\n" + + " } finally {\n" + + " System.out.println(\"Finally block\");\n" + + " }\n" + + " }\n" + + "} \n" + + "\n" + + "class Y implements AutoCloseable {\n" + + " public Y() throws WeirdException {\n" + + " throw new WeirdException();\n" + + " }\n" + + " public void close() {\n" + + " System.out.println(\"Closing resource\");\n" + + " }\n" + + "}\n" + + "\n" + + "class WeirdException extends Throwable {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (Y y = new Y();) {\n" + + " ^^^^^^^\n" + + "Unhandled exception type WeirdException\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (y == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Y why = new Y();\n" + + " ^^^^^^^\n" + + "Unhandled exception type WeirdException\n" + + "----------\n" + + "4. WARNING in X.java (at line 22)\n" + + " class WeirdException extends Throwable {}\n" + + " ^^^^^^^^^^^^^^\n" + + "The serializable class WeirdException does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// Resource nullness tests +public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) { \n" + + " try (Y y = new Y();) {\n" + + " if (y == null)\n {}\n" + + " }\n" + + " }\n" + + "} \n" + + "\n" + + "class Y implements AutoCloseable {\n" + + " public void close() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n"); +} +// Dead code tests, resource nullness, unhandled exception tests +public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) { \n" + + " try (Y y = new Y();) {\n" + + " if (y == null) {}\n" + + " Y why = new Y();\n" + + " System.out.println(\"Try block\");\n" + + " }\n" + + " }\n" + + "} \n" + + "\n" + + "class Y implements AutoCloseable {\n" + + " public Y() throws WeirdException {\n" + + " throw new WeirdException();\n" + + " }\n" + + " public void close() {\n" + + " System.out.println(\"Closing resource\");\n" + + " }\n" + + "}\n" + + "\n" + + "class WeirdException extends Throwable {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (Y y = new Y();) {\n" + + " ^^^^^^^\n" + + "Unhandled exception type WeirdException\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (y == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Y why = new Y();\n" + + " ^^^^^^^\n" + + "Unhandled exception type WeirdException\n" + + "----------\n" + + "4. WARNING in X.java (at line 20)\n" + + " class WeirdException extends Throwable {}\n" + + " ^^^^^^^^^^^^^^\n" + + "The serializable class WeirdException does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// Dead code tests +public void test017() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) { \n" + + " try (Y y = new Y();) {\n" + + " if (y == null)\n {}\n" + + " } finally {\n" + + " }\n" + + " }\n" + + "} \n" + + "\n" + + "class Y implements AutoCloseable {\n" + + " public void close() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n"); +} +// Syntax error tests +public void test018() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) { \n" + + " try () {\n" + + " } finally {\n" + + " }\n" + + " }\n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try () {\n" + + " ^\n" + + "Syntax error on token \"(\", Resources expected after this token\n" + + "----------\n"); +} +// Unhandled exception tests +public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) {\n" + + " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + + " throw new XXException();\n" + + " } catch (XException x) {\n" + + " } catch (YException y) {\n" + + " } catch (ZException z) {\n" + + " } finally {\n" + + " }\n" + + " }\n" + + " public X() throws XException {\n" + + " throw new XException();\n" + + " }\n" + + " public void close() throws XXException {\n" + + " throw new XXException();\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() throws YException {\n" + + " throw new YException();\n" + + " }\n" + + " public void close() throws YYException {\n" + + " throw new YYException();\n" + + " }\n" + + "}\n" + + "class Z implements AutoCloseable {\n" + + " public Z() throws ZException {\n" + + " throw new ZException();\n" + + " }\n" + + " public void close() throws ZZException {\n" + + " throw new ZZException();\n" + + " }\n" + + "}\n" + + "class XException extends Exception {}\n" + + "class XXException extends Exception {}\n" + + "class YException extends Exception {}\n" + + "class YYException extends Exception {}\n" + + "class ZException extends Exception {}\n" + + "class ZZException extends Exception {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + + " ^\n" + + "Unhandled exception type XXException thrown by automatic close() invocation on x\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + + " ^\n" + + "Unhandled exception type YYException thrown by automatic close() invocation on y\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + + " ^\n" + + "Unhandled exception type ZZException thrown by automatic close() invocation on z\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " throw new XXException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type XXException\n" + + "----------\n" + + "5. WARNING in X.java (at line 34)\n" + + " class XException extends Exception {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class XException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "6. WARNING in X.java (at line 35)\n" + + " class XXException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class XXException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "7. WARNING in X.java (at line 36)\n" + + " class YException extends Exception {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class YException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "8. WARNING in X.java (at line 37)\n" + + " class YYException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class YYException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "9. WARNING in X.java (at line 38)\n" + + " class ZException extends Exception {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class ZException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "10. WARNING in X.java (at line 39)\n" + + " class ZZException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// Resource type test +public void test021() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1(){\n" + + " try (Y i = null) {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public void close () {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (Y i = null) {\n" + + " ^\n" + + "The resource type Y does not implement java.lang.AutoCloseable\n" + + "----------\n"); +} +// Interface method return type compatibility test +public void test022() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1(){\n" + + " try (Y i = null) {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public int close () { return 0; }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " public int close () { return 0; }\n" + + " ^^^\n" + + "The return type is incompatible with AutoCloseable.close()\n" + + "----------\n"); +} +// Exception handling, compatibility tests +public void test023() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1(){\n" + + " try (Y i = null) {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public void close () throws Blah {}\n" + + "}\n" + + "class Blah extends Throwable {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (Y i = null) {\n" + + " ^\n" + + "Unhandled exception type Blah thrown by automatic close() invocation on i\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " public void close () throws Blah {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Exception Blah is not compatible with throws clause in AutoCloseable.close()\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " class Blah extends Throwable {}\n" + + " ^^^^\n" + + "The serializable class Blah does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// Exception handling tests +public void test024() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) {\n" + + " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + + " throw new XXException();\n" + + " } catch (XException x) {\n" + + " } catch (YException y) {\n" + + " } catch (ZException z) {\n" + + " } catch (XXException x) {\n" + + " } catch (YYException y) {\n" + + " } catch (ZZException z) {\n" + + " } finally {\n" + + " }\n" + + " }\n" + + " public X() throws XException {\n" + + " throw new XException();\n" + + " }\n" + + " public void close() throws XXException {\n" + + " throw new XXException();\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() throws YException {\n" + + " throw new YException();\n" + + " }\n" + + " public void close() throws YYException {\n" + + " throw new YYException();\n" + + " }\n" + + "}\n" + + "class Z implements AutoCloseable {\n" + + " public Z() throws ZException {\n" + + " throw new ZException();\n" + + " }\n" + + " public void close() throws ZZException {\n" + + " throw new ZZException();\n" + + " }\n" + + "}\n" + + "class XException extends Exception {}\n" + + "class XXException extends Exception {}\n" + + "class YException extends Exception {}\n" + + "class YYException extends Exception {}\n" + + "class ZException extends Exception {}\n" + + "class ZZException extends Exception {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 37)\n" + + " class XException extends Exception {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class XException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 38)\n" + + " class XXException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class XXException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 39)\n" + + " class YException extends Exception {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class YException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 40)\n" + + " class YYException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class YYException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "5. WARNING in X.java (at line 41)\n" + + " class ZException extends Exception {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class ZException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "6. WARNING in X.java (at line 42)\n" + + " class ZZException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// Unhandled exception tests +public void test025() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) {\n" + + " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + + " throw new XXException();\n" + + " } catch (XException x) {\n" + + " } catch (YException y) {\n" + + " } catch (ZException z) {\n" + + " \n" + + " }\n" + + " }\n" + + " public X() throws XException {\n" + + " throw new XException();\n" + + " }\n" + + " public void close() throws XXException {\n" + + " throw new XXException();\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() throws YException {\n" + + " throw new YException();\n" + + " }\n" + + " public void close() throws YYException {\n" + + " throw new YYException();\n" + + " }\n" + + "}\n" + + "class Z implements AutoCloseable {\n" + + " public Z() throws ZException {\n" + + " throw new ZException();\n" + + " }\n" + + " public void close() throws ZZException {\n" + + " throw new ZZException();\n" + + " }\n" + + "}\n" + + "class XException extends Exception {}\n" + + "class XXException extends Exception {}\n" + + "class YException extends Exception {}\n" + + "class YYException extends Exception {}\n" + + "class ZException extends Exception {}\n" + + "class ZZException extends Exception {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + + " ^\n" + + "Unhandled exception type XXException thrown by automatic close() invocation on x\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + + " ^\n" + + "Unhandled exception type YYException thrown by automatic close() invocation on y\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + + " ^\n" + + "Unhandled exception type ZZException thrown by automatic close() invocation on z\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " throw new XXException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type XXException\n" + + "----------\n" + + "5. WARNING in X.java (at line 34)\n" + + " class XException extends Exception {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class XException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "6. WARNING in X.java (at line 35)\n" + + " class XXException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class XXException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "7. WARNING in X.java (at line 36)\n" + + " class YException extends Exception {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class YException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "8. WARNING in X.java (at line 37)\n" + + " class YYException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class YYException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "9. WARNING in X.java (at line 38)\n" + + " class ZException extends Exception {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class ZException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "10. WARNING in X.java (at line 39)\n" + + " class ZZException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +public void test026() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) {\n" + + " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + + " throw new XXException();\n" + + " } catch (XException x) {\n" + + " } catch (YException y) {\n" + + " } catch (ZException z) {\n" + + " } catch (XXException x) {\n" + + " } catch (YYException y) {\n" + + " } catch (ZZException z) {\n\n" + + " }\n" + + " }\n" + + " public X() throws XException {\n" + + " throw new XException();\n" + + " }\n" + + " public void close() throws XXException {\n" + + " throw new XXException();\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() throws YException {\n" + + " throw new YException();\n" + + " }\n" + + " public void close() throws YYException {\n" + + " throw new YYException();\n" + + " }\n" + + "}\n" + + "class Z implements AutoCloseable {\n" + + " public Z() throws ZException {\n" + + " throw new ZException();\n" + + " }\n" + + " public void close() throws ZZException {\n" + + " throw new ZZException();\n" + + " }\n" + + "}\n" + + "class XException extends Exception {}\n" + + "class XXException extends Exception {}\n" + + "class YException extends Exception {}\n" + + "class YYException extends Exception {}\n" + + "class ZException extends Exception {}\n" + + "class ZZException extends Exception {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 37)\n" + + " class XException extends Exception {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class XException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 38)\n" + + " class XXException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class XXException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 39)\n" + + " class YException extends Exception {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class YException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. WARNING in X.java (at line 40)\n" + + " class YYException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class YYException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "5. WARNING in X.java (at line 41)\n" + + " class ZException extends Exception {}\n" + + " ^^^^^^^^^^\n" + + "The serializable class ZException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "6. WARNING in X.java (at line 42)\n" + + " class ZZException extends Exception {}\n" + + " ^^^^^^^^^^^\n" + + "The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +public void test027() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) throws Exception {\n" + + " try (X x = new X(); Y y = new Y()) {\n" + + " System.out.println(\"Body\");\n" + + " throw new Exception(\"Body\");\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable [] suppressed = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; i++) {\n" + + " System.out.println(\"Suppressed:\" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " int finallyVar = 10;\n" + + " System.out.println(finallyVar);\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " System.out.println(\"X CTOR\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"X Close\");\n" + + " throw new Exception(\"X Close\");\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() {\n" + + " System.out.println(\"Y CTOR\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Y Close\");\n" + + " throw new Exception(\"Y Close\");\n" + + " }\n" + + "}\n" + }, + "X CTOR\n" + + "Y CTOR\n" + + "Body\n" + + "Y Close\n" + + "X Close\n" + + "java.lang.Exception: Body\n" + + "Suppressed:java.lang.Exception: Y Close\n" + + "Suppressed:java.lang.Exception: X Close\n" + + "10"); +} +public void test028() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) throws Exception {\n" + + " try (X x = new X(); Y y = new Y()) {\n" + + " System.out.println(\"Body\");\n" + + " } catch (Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " System.out.println(\"X CTOR\");\n" + + " }\n" + + " public void close() {\n" + + " System.out.println(\"X DTOR\");\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() {\n" + + " System.out.println(\"Y CTOR\");\n" + + " }\n" + + " public void close() {\n" + + " System.out.println(\"Y DTOR\");\n" + + " }\n" + + "}\n" + }, + "X CTOR\n" + + "Y CTOR\n" + + "Body\n" + + "Y DTOR\n" + + "X DTOR"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338881 +public void test029() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileReader;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() {\n" + + " File file = new File(\"somefile\");\n" + + " try(FileReader fileReader = new FileReader(file);) {\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " } catch (IOException e) {\n" + + " System.out.println(\"Got IO exception\");\n" + + " } finally{\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "Got IO exception"); +} +public void test030() { // test return + resources + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) throws Exception { \n" + + " final boolean getOut = true;\n" + + " System.out.println(\"Main\");\n" + + " try (X x1 = new X(); X x2 = new X()) {\n" + + " System.out.println(\"Outer Try\");\n" + + " while (true) {\n" + + " try (Y y1 = new Y(); Y y2 = new Y()) {\n" + + " System.out.println(\"Middle Try\");\n" + + " try (Z z1 = new Z(); Z z2 = new Z()) {\n" + + " System.out.println(\"Inner Try\");\n" + + " if (getOut) \n" + + " return;\n" + + " else\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + " System.out.println(\"Out of while\");\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " System.out.println(\"X::X\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"X::~X\");\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() {\n" + + " System.out.println(\"Y::Y\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Y::~Y\");\n" + + " }\n" + + "}\n" + + "class Z implements AutoCloseable {\n" + + " public Z() {\n" + + " System.out.println(\"Z::Z\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Z::~Z\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "X::X\n" + + "X::X\n" + + "Outer Try\n" + + "Y::Y\n" + + "Y::Y\n" + + "Middle Try\n" + + "Z::Z\n" + + "Z::Z\n" + + "Inner Try\n" + + "Z::~Z\n" + + "Z::~Z\n" + + "Y::~Y\n" + + "Y::~Y\n" + + "X::~X\n" + + "X::~X"); +} +public void test030a() { // test return + resources + with exceptions being thrown by close() + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) throws Exception { \n" + + " final boolean getOut = true;\n" + + " System.out.println(\"Main\");\n" + + " try (X x1 = new X(); X x2 = new X()) {\n" + + " System.out.println(\"Outer Try\");\n" + + " while (true) {\n" + + " try (Y y1 = new Y(); Y y2 = new Y()) {\n" + + " System.out.println(\"Middle Try\");\n" + + " try (Z z1 = new Z(); Z z2 = new Z()) {\n" + + " System.out.println(\"Inner Try\");\n" + + " if (getOut) \n" + + " return;\n" + + " else\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + " System.out.println(\"Out of while\");\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " System.out.println(\"X::X\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"X::~X\");\n" + + " throw new Exception(\"X::~X\");\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() {\n" + + " System.out.println(\"Y::Y\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Y::~Y\");\n" + + " throw new Exception(\"Y::~Y\");\n" + + " }\n" + + "}\n" + + "class Z implements AutoCloseable {\n" + + " public Z() {\n" + + " System.out.println(\"Z::Z\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Z::~Z\");\n" + + " throw new Exception(\"Z::~Z\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "X::X\n" + + "X::X\n" + + "Outer Try\n" + + "Y::Y\n" + + "Y::Y\n" + + "Middle Try\n" + + "Z::Z\n" + + "Z::Z\n" + + "Inner Try\n" + + "Z::~Z\n" + + "Z::~Z\n" + + "Y::~Y\n" + + "Y::~Y\n" + + "X::~X\n" + + "X::~X\n" + + "java.lang.Exception: Z::~Z\n" + + "Suppressed: java.lang.Exception: Z::~Z\n" + + "Suppressed: java.lang.Exception: Y::~Y\n" + + "Suppressed: java.lang.Exception: Y::~Y\n" + + "Suppressed: java.lang.Exception: X::~X\n" + + "Suppressed: java.lang.Exception: X::~X"); +} +public void test031() { // test break + resources + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) throws Exception { \n" + + " final boolean getOut = false;\n" + + " System.out.println(\"Main\");\n" + + " try (X x1 = new X(); X x2 = new X()) {\n" + + " System.out.println(\"Outer Try\");\n" + + " while (true) {\n" + + " try (Y y1 = new Y(); Y y2 = new Y()) {\n" + + " System.out.println(\"Middle Try\");\n" + + " try (Z z1 = new Z(); Z z2 = new Z()) {\n" + + " System.out.println(\"Inner Try\");\n" + + " if (getOut) \n" + + " return;\n" + + " else\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + " System.out.println(\"Out of while\");\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " System.out.println(\"X::X\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"X::~X\");\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() {\n" + + " System.out.println(\"Y::Y\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Y::~Y\");\n" + + " }\n" + + "}\n" + + "class Z implements AutoCloseable {\n" + + " public Z() {\n" + + " System.out.println(\"Z::Z\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Z::~Z\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "X::X\n" + + "X::X\n" + + "Outer Try\n" + + "Y::Y\n" + + "Y::Y\n" + + "Middle Try\n" + + "Z::Z\n" + + "Z::Z\n" + + "Inner Try\n" + + "Z::~Z\n" + + "Z::~Z\n" + + "Y::~Y\n" + + "Y::~Y\n" + + "Out of while\n" + + "X::~X\n" + + "X::~X"); +} +public void test032() { // test continue + resources + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) throws Exception { \n" + + " final boolean getOut = false;\n" + + " System.out.println(\"Main\");\n" + + " try (X x1 = new X(); X x2 = new X()) {\n" + + " System.out.println(\"Outer Try\");\n" + + " boolean more = true;\n" + + " while (more) {\n" + + " try (Y y1 = new Y(); Y y2 = new Y()) {\n" + + " System.out.println(\"Middle Try\");\n" + + " try (Z z1 = new Z(); Z z2 = new Z()) {\n" + + " System.out.println(\"Inner Try\");\n" + + " more = false;\n" + + " continue;\n" + + " } finally { \n" + + " System.out.println(\"Inner Finally\");\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"Middle Finally\");\n" + + " }\n" + + " }\n" + + " System.out.println(\"Out of while\");\n" + + " } finally {\n" + + " System.out.println(\"Outer Finally\");\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " System.out.println(\"X::X\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"X::~X\");\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() {\n" + + " System.out.println(\"Y::Y\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Y::~Y\");\n" + + " }\n" + + "}\n" + + "class Z implements AutoCloseable {\n" + + " public Z() {\n" + + " System.out.println(\"Z::Z\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Z::~Z\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "X::X\n" + + "X::X\n" + + "Outer Try\n" + + "Y::Y\n" + + "Y::Y\n" + + "Middle Try\n" + + "Z::Z\n" + + "Z::Z\n" + + "Inner Try\n" + + "Z::~Z\n" + + "Z::~Z\n" + + "Inner Finally\n" + + "Y::~Y\n" + + "Y::~Y\n" + + "Middle Finally\n" + + "Out of while\n" + + "X::~X\n" + + "X::~X\n" + + "Outer Finally"); +} +public void test033() { // test null resources + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " public static void main(String [] args) throws Exception { \n" + + " final boolean getOut = false;\n" + + " System.out.println(\"Main\");\n" + + " try (X x1 = null; Y y = new Y(); Z z = null) {\n" + + " System.out.println(\"Body\");\n" + + " } finally {\n" + + " System.out.println(\"Outer Finally\");\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " System.out.println(\"X::X\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"X::~X\");\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public Y() {\n" + + " System.out.println(\"Y::Y\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Y::~Y\");\n" + + " }\n" + + "}\n" + + "class Z implements AutoCloseable {\n" + + " public Z() {\n" + + " System.out.println(\"Z::Z\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Z::~Z\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "Y::Y\n" + + "Body\n" + + "Y::~Y\n" + + "Outer Finally"); +} +public void test034() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " throw new Exception(\"Body\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " throw new Exception (\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " throw new Exception (\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " throw new Exception (\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " throw new Exception (\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " throw new Exception (\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " throw new Exception (\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " throw new Exception (\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " throw new Exception (\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " throw new Exception (\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " throw new Exception (\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " throw new Exception (\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "java.lang.Exception: A::A\n" + + "All done"); +} +public void test035() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " throw new Exception(\"Body\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " throw new Exception (\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " throw new Exception (\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " throw new Exception (\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " throw new Exception (\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " throw new Exception (\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " throw new Exception (\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " throw new Exception (\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " throw new Exception (\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " throw new Exception (\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " throw new Exception (\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "A::~A\n" + + "java.lang.Exception: B::B\n" + + "Suppressed: java.lang.Exception: A::~A\n" + + "All done"); +} +public void test036() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " throw new Exception(\"Body\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " throw new Exception (\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " throw new Exception (\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " throw new Exception (\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " throw new Exception (\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " throw new Exception (\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " throw new Exception (\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " throw new Exception (\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " throw new Exception (\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " throw new Exception (\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "Outer try\n" + + "C::C\n" + + "B::~B\n" + + "A::~A\n" + + "java.lang.Exception: C::C\n" + + "Suppressed: java.lang.Exception: B::~B\n" + + "Suppressed: java.lang.Exception: A::~A\n" + + "All done"); +} +public void test037() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " throw new Exception(\"Body\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " throw new Exception (\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " throw new Exception (\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " throw new Exception (\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " throw new Exception (\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " throw new Exception (\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " throw new Exception (\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " throw new Exception (\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " throw new Exception (\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "Outer try\n" + + "C::C\n" + + "D::D\n" + + "C::~C\n" + + "B::~B\n" + + "A::~A\n" + + "java.lang.Exception: D::D\n" + + "Suppressed: java.lang.Exception: C::~C\n" + + "Suppressed: java.lang.Exception: B::~B\n" + + "Suppressed: java.lang.Exception: A::~A\n" + + "All done"); +} +public void test038() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " throw new Exception(\"Body\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " throw new Exception (\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " throw new Exception (\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " throw new Exception (\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " throw new Exception (\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " throw new Exception (\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " throw new Exception (\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " throw new Exception (\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "Outer try\n" + + "C::C\n" + + "D::D\n" + + "Middle try\n" + + "E::E\n" + + "D::~D\n" + + "C::~C\n" + + "B::~B\n" + + "A::~A\n" + + "java.lang.Exception: E::E\n" + + "Suppressed: java.lang.Exception: D::~D\n" + + "Suppressed: java.lang.Exception: C::~C\n" + + "Suppressed: java.lang.Exception: B::~B\n" + + "Suppressed: java.lang.Exception: A::~A\n" + + "All done"); +} +public void test039() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " throw new Exception(\"Body\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " throw new Exception (\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " throw new Exception (\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " throw new Exception (\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " throw new Exception (\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " throw new Exception (\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " throw new Exception (\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "Outer try\n" + + "C::C\n" + + "D::D\n" + + "Middle try\n" + + "E::E\n" + + "F::F\n" + + "E::~E\n" + + "D::~D\n" + + "C::~C\n" + + "B::~B\n" + + "A::~A\n" + + "java.lang.Exception: F::F\n" + + "Suppressed: java.lang.Exception: E::~E\n" + + "Suppressed: java.lang.Exception: D::~D\n" + + "Suppressed: java.lang.Exception: C::~C\n" + + "Suppressed: java.lang.Exception: B::~B\n" + + "Suppressed: java.lang.Exception: A::~A\n" + + "All done"); +} +public void test040() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " throw new Exception(\"Body\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " throw new Exception (\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " throw new Exception (\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " throw new Exception (\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " throw new Exception (\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " throw new Exception (\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "Outer try\n" + + "C::C\n" + + "D::D\n" + + "Middle try\n" + + "E::E\n" + + "F::F\n" + + "Inner try\n" + + "F::~F\n" + + "E::~E\n" + + "D::~D\n" + + "C::~C\n" + + "B::~B\n" + + "A::~A\n" + + "java.lang.Exception: Body\n" + + "Suppressed: java.lang.Exception: F::~F\n" + + "Suppressed: java.lang.Exception: E::~E\n" + + "Suppressed: java.lang.Exception: D::~D\n" + + "Suppressed: java.lang.Exception: C::~C\n" + + "Suppressed: java.lang.Exception: B::~B\n" + + "Suppressed: java.lang.Exception: A::~A\n" + + "All done"); +} +public void test041() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " throw new Exception (\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " throw new Exception (\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " throw new Exception (\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " throw new Exception (\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " throw new Exception (\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "Outer try\n" + + "C::C\n" + + "D::D\n" + + "Middle try\n" + + "E::E\n" + + "F::F\n" + + "Inner try\n" + + "F::~F\n" + + "E::~E\n" + + "D::~D\n" + + "C::~C\n" + + "B::~B\n" + + "A::~A\n" + + "java.lang.Exception: F::~F\n" + + "Suppressed: java.lang.Exception: E::~E\n" + + "Suppressed: java.lang.Exception: D::~D\n" + + "Suppressed: java.lang.Exception: C::~C\n" + + "Suppressed: java.lang.Exception: B::~B\n" + + "Suppressed: java.lang.Exception: A::~A\n" + + "All done"); +} +public void test042() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " throw new Exception (\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " throw new Exception (\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " throw new Exception (\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " throw new Exception (\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "Outer try\n" + + "C::C\n" + + "D::D\n" + + "Middle try\n" + + "E::E\n" + + "F::F\n" + + "Inner try\n" + + "F::~F\n" + + "E::~E\n" + + "D::~D\n" + + "C::~C\n" + + "B::~B\n" + + "A::~A\n" + + "java.lang.Exception: E::~E\n" + + "Suppressed: java.lang.Exception: D::~D\n" + + "Suppressed: java.lang.Exception: C::~C\n" + + "Suppressed: java.lang.Exception: B::~B\n" + + "Suppressed: java.lang.Exception: A::~A\n" + + "All done"); +} +public void test043() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " throw new Exception (\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " throw new Exception (\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " throw new Exception (\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "Outer try\n" + + "C::C\n" + + "D::D\n" + + "Middle try\n" + + "E::E\n" + + "F::F\n" + + "Inner try\n" + + "F::~F\n" + + "E::~E\n" + + "D::~D\n" + + "C::~C\n" + + "B::~B\n" + + "A::~A\n" + + "java.lang.Exception: D::~D\n" + + "Suppressed: java.lang.Exception: C::~C\n" + + "Suppressed: java.lang.Exception: B::~B\n" + + "Suppressed: java.lang.Exception: A::~A\n" + + "All done"); +} +public void test044() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " throw new Exception (\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " throw new Exception (\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "Outer try\n" + + "C::C\n" + + "D::D\n" + + "Middle try\n" + + "E::E\n" + + "F::F\n" + + "Inner try\n" + + "F::~F\n" + + "E::~E\n" + + "D::~D\n" + + "C::~C\n" + + "B::~B\n" + + "A::~A\n" + + "java.lang.Exception: C::~C\n" + + "Suppressed: java.lang.Exception: B::~B\n" + + "Suppressed: java.lang.Exception: A::~A\n" + + "All done"); +} +public void test045() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " throw new Exception (\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "Outer try\n" + + "C::C\n" + + "D::D\n" + + "Middle try\n" + + "E::E\n" + + "F::F\n" + + "Inner try\n" + + "F::~F\n" + + "E::~E\n" + + "D::~D\n" + + "C::~C\n" + + "B::~B\n" + + "A::~A\n" + + "java.lang.Exception: B::~B\n" + + "Suppressed: java.lang.Exception: A::~A\n" + + "All done"); +} +public void test046() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " throw new Exception (\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "Outer try\n" + + "C::C\n" + + "D::D\n" + + "Middle try\n" + + "E::E\n" + + "F::F\n" + + "Inner try\n" + + "F::~F\n" + + "E::~E\n" + + "D::~D\n" + + "C::~C\n" + + "B::~B\n" + + "A::~A\n" + + "java.lang.Exception: A::~A\n" + + "All done"); +} +public void test047() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A(); B b = new B()) {\n" + + " System.out.println(\"Outer try\");\n" + + " try (C c = new C(); D d = new D();) {\n" + + " System.out.println(\"Middle try\");\n" + + " try (E e = new E(); F f = new F()) {\n" + + " System.out.println(\"Inner try\");\n" + + " } \n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " }\n" + + "}\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " }\n" + + "}\n" + + "class D implements AutoCloseable {\n" + + " public D () throws Exception {\n" + + " System.out.println(\"D::D\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"D::~D\");\n" + + " }\n" + + "}\n" + + "class E implements AutoCloseable {\n" + + " public E () throws Exception {\n" + + " System.out.println(\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " }\n" + + "}\n" + + "class F implements AutoCloseable {\n" + + " public F () throws Exception {\n" + + " System.out.println(\"F::F\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"F::~F\");\n" + + " }\n" + + "}\n" + + "class G implements AutoCloseable {\n" + + " public G () throws Exception {\n" + + " System.out.println(\"G::G\");\n" + + " throw new Exception (\"G::G\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"G::~G\");\n" + + " throw new Exception (\"G::~G\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "B::B\n" + + "Outer try\n" + + "C::C\n" + + "D::D\n" + + "Middle try\n" + + "E::E\n" + + "F::F\n" + + "Inner try\n" + + "F::~F\n" + + "E::~E\n" + + "D::~D\n" + + "C::~C\n" + + "B::~B\n" + + "A::~A\n" + + "All done"); +} +public void test048() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (A a = new A()) {\n" + + " System.out.println(\"X::Try\");\n" + + " throw new Exception(\"X::Main\");\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class A implements AutoCloseable {\n" + + " public A () throws Exception {\n" + + " System.out.println(\"A::A\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"A::~A\");\n" + + " try (B b = new B()) {\n" + + " System.out.println(\"A::~A::Try\");\n" + + " throw new Exception(\"A::~A\");\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " throw e;\n" + + " } \n" + + " }\n" + + "}\n" + + "\n" + + "class B implements AutoCloseable {\n" + + " public B () throws Exception {\n" + + " System.out.println(\"B::B\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"B::~B\");\n" + + " try (C c = new C()) {\n" + + " System.out.println(\"B::~B::Try\");\n" + + " throw new Exception (\"B::~B\");\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " throw e;\n" + + " } \n" + + " }\n" + + "}\n" + + "class C implements AutoCloseable {\n" + + " public C () throws Exception {\n" + + " System.out.println(\"C::C\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"C::~C\");\n" + + " throw new Exception (\"C::~C\");\n" + + " } \n" + + "}\n" + }, + "Main\n" + + "A::A\n" + + "X::Try\n" + + "A::~A\n" + + "B::B\n" + + "A::~A::Try\n" + + "B::~B\n" + + "C::C\n" + + "B::~B::Try\n" + + "C::~C\n" + + "java.lang.Exception: B::~B\n" + + "Suppressed: java.lang.Exception: C::~C\n" + + "java.lang.Exception: A::~A\n" + + "Suppressed: java.lang.Exception: B::~B\n" + + "java.lang.Exception: X::Main\n" + + "Suppressed: java.lang.Exception: A::~A\n" + + "All done"); +} +//ensure that it doesn't completely fail when using TWR and 1.5 mode +public void test049() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileReader;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() {\n" + + " File file = new File(\"somefile\");\n" + + " try(FileReader fileReader = new FileReader(file);) {\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " } catch (IOException e) {\n" + + " System.out.println(\"Got IO exception\");\n" + + " } finally{\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " try(FileReader fileReader = new FileReader(file);) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource specification not allowed here for source level below 1.7\n" + + "----------\n", + null, + true, + options); +} +public void test050() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Main\");\n" + + " try (E e = E.CONST) {\n" + + " System.out.println(\"Outer try\");\n" + + " } catch (Exception e) {\n" + + " System.out.println(e);\n" + + " Throwable suppressed [] = e.getSuppressed();\n" + + " for (int i = 0; i < suppressed.length; ++i) {\n" + + " System.out.println(\"Suppressed: \" + suppressed[i]);\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"All done\");\n" + + " }\n" + + " }\n" + + "}", + "E.java", + "public enum E implements AutoCloseable {\n" + + " CONST;\n" + + " private E () {\n" + + " System.out.println(\"E::E\");\n" + + " }\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"E::~E\");\n" + + " throw new Exception (\"E::~E\");\n" + + " }\n" + + "}" + }, + "Main\n" + + "E::E\n" + + "Outer try\n" + + "E::~E\n" + + "java.lang.Exception: E::~E\n" + + "All done"); +} +public void test051() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " try (Test t = new Test()) {\n" + + " for (int i = 0; i < 10; i++) {\n" + + " }\n" + + "\n" + + "\n" + + " } \n" + + "\n" + + " catch (Exception e) {\n" + + " StackTraceElement t = e.getStackTrace()[1];\n" + + " String file = t.getFileName();\n" + + " int line = t.getLineNumber();\n" + + " System.out.println(\"File = \" + file + \" \" + \"line = \" + line);\n" + + " }\n" + + " }\n" + + "}\n" + + "class Test implements AutoCloseable {\n" + + " public void close() throws Exception {\n" + + " throw new Exception();\n" + + " }\n" + + "}\n" + }, + "File = X.java line = 8"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348406 +public void test052() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " try (Test t = new Test()) {\n" + + " } \n" + + " }\n" + + "}\n" + + "class Test {\n" + + " public void close() throws Exception {\n" + + " throw new Exception();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (Test t = new Test()) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Resource specification not allowed here for source level below 1.7\n" + + "----------\n", + null, + true, + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348705 +// Unhandled exception due to autoclose should be reported separately +public void test053() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1(){\n" + + " try (Y y = new Y()) { \n" + + " y.close();\n" + + " System.out.println();\n" + + " } catch (RuntimeException e) {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y implements Managed {\n" + + " public Y() throws CloneNotSupportedException {}\n" + + " public void close () throws ClassNotFoundException, java.io.IOException {\n" + + " }\n" + + "}\n" + + "interface Managed extends AutoCloseable {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (Y y = new Y()) { \n" + + " ^\n" + + "Unhandled exception type ClassNotFoundException thrown by automatic close() invocation on y\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " try (Y y = new Y()) { \n" + + " ^\n" + + "Unhandled exception type IOException thrown by automatic close() invocation on y\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " try (Y y = new Y()) { \n" + + " ^^^^^^^\n" + + "Unhandled exception type CloneNotSupportedException\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " y.close();\n" + + " ^^^^^^^^^\n" + + "Unhandled exception type ClassNotFoundException\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " y.close();\n" + + " ^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=349862 (NPE when union type is used in the resource section.) +public void test054() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " try (Object | Integer res = null) {\n" + + " } catch (Exception e) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (Object | Integer res = null) {\n" + + " ^\n" + + "Syntax error on token \"|\", . expected\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=349862 (NPE when union type is used in the resource section.) +public void test054a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " try (Object.Integer res = null) {\n" + + " } catch (Exception e) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (Object.Integer res = null) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Object.Integer cannot be resolved to a type\n" + + "----------\n"); +} +public static Class testClass() { + return TryWithResourcesStatementTest.class; +} +} diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UnderscoresInLiteralsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UnderscoresInLiteralsTest.java new file mode 100644 index 0000000000..cf487a18b5 --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UnderscoresInLiteralsTest.java @@ -0,0 +1,439 @@ +/******************************************************************************* + * Copyright (c) 2011 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 + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class UnderscoresInLiteralsTest extends AbstractRegressionTest { + static { +// TESTS_NUMBERS = new int[] { 24 }; + } + public UnderscoresInLiteralsTest(String name) { + super(name); + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_7); + } + + public static Class testClass() { + return UnderscoresInLiteralsTest.class; + } + + public void test001() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0b_001);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0b_001);\n" + + " ^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0_b001);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0_b001);\n" + + " ^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0b001_);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0b001_);\n" + + " ^^^^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0x_11.0p33f);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0x_11.0p33f);\n" + + " ^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0x11_.0p33f);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0x11_.0p33f);\n" + + " ^^^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0x11._0p33f);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0x11._0p33f);\n" + + " ^^^^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0x11.0_p33f);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0x11.0_p33f);\n" + + " ^^^^^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0x11.0p_33f);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0x11.0p_33f);\n" + + " ^^^^^^^^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0x11.0p33_f);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0x11.0p33_f);\n" + + " ^^^^^^^^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0x_0001AEFBBA);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0x_0001AEFBBA);\n" + + " ^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0_x0001AEFBBA);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0_x0001AEFBBA);\n" + + " ^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0x0001AEFBBA_);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0x0001AEFBBA_);\n" + + " ^^^^^^^^^^^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(_01234567);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(_01234567);\n" + + " ^^^^^^^^^\n" + + "_01234567 cannot be resolved to a variable\n" + + "----------\n"); + } + public void test014() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(01234567_);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(01234567_);\n" + + " ^^^^^^^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(1_.236589954f);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(1_.236589954f);\n" + + " ^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(1._236589954f);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(1._236589954f);\n" + + " ^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test017() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(1_e2);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(1_e2);\n" + + " ^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test018() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(1e_2);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(1e_2);\n" + + " ^^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test019() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(1e2_);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(1e2_);\n" + + " ^^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(01e2_);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(01e2_);\n" + + " ^^^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test021() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(01_e2_);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(01_e2_);\n" + + " ^^^\n" + + "Underscores have to be located within digits\n" + + "----------\n"); + } + public void test022() { + Map customedOptions = getCompilerOptions(); + customedOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); + customedOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); + customedOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0b1110000_);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(0b1110000_);\n" + + " ^^^^^^^^^^\n" + + "Underscores can only be used with source level 1.7 or greater\n" + + "----------\n", + null, + true, + customedOptions); + } + public void test023() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0x1234____5678____90L);\n" + + " }\n" + + "}" + }, + "78187493520"); + } + public void test024() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(90_00__00_0);\n" + + " }\n" + + "}" + }, + "9000000"); + } +} diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java index 7d3390fae6..30e7dc775e 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java @@ -4,7 +4,7 @@ * 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 *******************************************************************************/ @@ -13,6 +13,7 @@ package org.eclipse.jdt.core.tests.compiler.regression; import java.io.File; import java.util.Map; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.ToolFactory; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.util.IClassFileAttribute; @@ -33,7 +34,7 @@ public class VarargsTest extends AbstractComparableTest { // All specified tests which does not belong to the class are skipped... static { // TESTS_NAMES = new String[] { "test000" }; -// TESTS_NUMBERS = new int[] { 62 }; +// TESTS_NUMBERS = new int[] { 61 }; // TESTS_RANGE = new int[] { 11, -1 }; } public static Test suite() { @@ -2144,6 +2145,27 @@ public class VarargsTest extends AbstractComparableTest { } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=223427 public void test061() { + String expectedOutput = + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Collections.addAll(constantClassSet, String.class, Object.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Class<? extends Object> is created for a varargs parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + expectedOutput = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + } this.runNegativeTest( new String[] { "X.java", @@ -2156,17 +2178,7 @@ public class VarargsTest extends AbstractComparableTest { " }\n" + "}\n", // ================= }, - "----------\n" + - "1. WARNING in X.java (at line 5)\n" + - " Collections.addAll(constantClassSet, String.class, Object.class);\n" + - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Class<? extends Object> is created for a varargs parameter\n" + - "----------\n" + - "2. ERROR in X.java (at line 6)\n" + - " Zork z;\n" + - " ^^^^\n" + - "Zork cannot be resolved to a type\n" + - "----------\n"); + expectedOutput); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=328247 public void test062() throws Exception { @@ -2196,8 +2208,137 @@ public class VarargsTest extends AbstractComparableTest { " X$1(X arg0, java.lang.Integer $anonymous0, java.lang.String... $anonymous1, java.lang.Float arg3);\n"; checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X$1.class", "X$1", expectedOutput); } + //safe varargs support + public void test063() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + this.runConformTest( + new String[] { + "java/lang/SafeVarargs.java", + "package java.lang;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "import static java.lang.annotation.ElementType.CONSTRUCTOR;\n" + + "import static java.lang.annotation.ElementType.METHOD;\n" + + "\n" + + "@Retention(value=RUNTIME)\n" + + "@Target(value={CONSTRUCTOR,METHOD})\n" + + "public @interface SafeVarargs {}", + "Y.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class Y {\r\n" + + " @SafeVarargs\n" + + " public static <T> List<T> asList(T... a) {\n" + + " return null;\n" + + " }\n" + + "}", + }, + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\r\n" + + " public void bar() {\n" + + " List<? extends Class<?>> classes = Y.asList(String.class, Boolean.class);\n" + + " }\n" + + "}", + }, + "", + null, + false, + null, + options, + null); + } + public void test064() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + this.runConformTest( + new String[] { + "java/lang/SafeVarargs.java", + "package java.lang;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "import static java.lang.annotation.ElementType.CONSTRUCTOR;\n" + + "import static java.lang.annotation.ElementType.METHOD;\n" + + "\n" + + "@Retention(value=RUNTIME)\n" + + "@Target(value={CONSTRUCTOR,METHOD})\n" + + "public @interface SafeVarargs {}", + }, + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\r\n" + + " @SafeVarargs\n" + + " public static <T> List<T> asList(T... a) {\n" + + " return null;\n" + + " }\n" + + " public void bar() {\n" + + " List<? extends Class<?>> classes = X.asList(String.class, Boolean.class);\n" + + " }\n" + + "}", + }, + "", + null, + false, + null, + options, + null); + } + public void test065() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + this.runConformTest( + new String[] { + "java/lang/SafeVarargs.java", + "package java.lang;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "import static java.lang.annotation.ElementType.CONSTRUCTOR;\n" + + "import static java.lang.annotation.ElementType.METHOD;\n" + + "\n" + + "@Retention(value=RUNTIME)\n" + + "@Target(value={CONSTRUCTOR,METHOD})\n" + + "public @interface SafeVarargs {}", + }, + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\r\n" + + " @SafeVarargs\n" + + " public static <T> List<T> asList(T... a) {\n" + + " return null;\n" + + " }\n" + + " public void bar() {\n" + + " List<List<String>> classes = X.asList(X.asList(\"Hello\", \"World\"));\n" + + " }\n" + + "}", + }, + "", + null, + false, + null, + options, + null); + } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337093 - public void test063() { + public void test066() { Map options = getCompilerOptions(); options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); this.runNegativeTest( @@ -2224,14 +2365,395 @@ public class VarargsTest extends AbstractComparableTest { " }\n" + "}\n", // ================= }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? "----------\n" + "1. WARNING in X.java (at line 18)\n" + " new IteratorChain<Number>(null, null);\n" + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Type safety : A generic array of Collection<? extends Number> is created for a varargs parameter\n" + + "Type safety: A generic array of Collection<? extends Number> is created for a varargs parameter\n" + + "----------\n": + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public IteratorChain(Collection<? extends T> a, Collection<? extends T> b, Collection<? extends T> ... collections) {\n" + + " ^^^^^^^^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter collections\n" + + "----------\n" + + "2. WARNING in X.java (at line 18)\n" + + " new IteratorChain<Number>(null, null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Collection<? extends Number> is created for a varargs parameter\n" + "----------\n", null, true, options); } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337799 + public void test067() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + this.runConformTest( + new String[] { + "java/lang/SafeVarargs.java", + "package java.lang;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "import static java.lang.annotation.ElementType.CONSTRUCTOR;\n" + + "import static java.lang.annotation.ElementType.METHOD;\n" + + "\n" + + "@Retention(value=RUNTIME)\n" + + "@Target(value={CONSTRUCTOR,METHOD})\n" + + "public @interface SafeVarargs {}", + }, + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " @SafeVarargs\n" + + " public static <T> List<T> asList() { // Error, not varargs\n" + + " return null;\n" + + " }\n" + + " @SafeVarargs\n" + + " public <T> List<T> asList2(T ... a) { // error not static or final\n" + + " return null;\n" + + " }\n" + + " @SafeVarargs\n" + + " public static <T> List<T> asList3(T ... a) { // OK, varargs & static\n" + + " return null;\n" + + " }\n" + + " @SafeVarargs\n" + + " public final <T> List<T> asList4(T ... a) { // OK varargs & final\n" + + " return null;\n" + + " }\n" + + " @SafeVarargs\n" + + " public final static <T> List<T> asList5(T ... a) { // OK, varargs & static & final\n" + + " return null;\n" + + " }\n" + + " @SafeVarargs\n" + + " public int b;\n" + + "}\n" + + "interface I {\n" + + " @SafeVarargs\n" + + " public <T> List<T> asList(T ... t);\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public static <T> List<T> asList() { // Error, not varargs\n" + + " ^^^^^^^^\n" + + "@SafeVarargs annotation cannot be applied to fixed arity method asList\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " public <T> List<T> asList2(T ... a) { // error not static or final\n" + + " ^^^^^^^^^^^^^^^^\n" + + "@SafeVarargs annotation cannot be applied to non-final instance method asList2\n" + + "----------\n" + + "3. ERROR in X.java (at line 23)\n" + + " @SafeVarargs\n" + + " ^^^^^^^^^^^^\n" + + "The annotation @SafeVarargs is disallowed for this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 28)\n" + + " public <T> List<T> asList(T ... t);\n" + + " ^^^^^^^^^^^^^^^\n" + + "@SafeVarargs annotation cannot be applied to non-final instance method asList\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337799 + public void test067b() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + this.runConformTest( + new String[] { + "java/lang/SafeVarargs.java", + "package java.lang;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "import static java.lang.annotation.ElementType.CONSTRUCTOR;\n" + + "import static java.lang.annotation.ElementType.METHOD;\n" + + "\n" + + "@Retention(value=RUNTIME)\n" + + "@Target(value={CONSTRUCTOR,METHOD})\n" + + "public @interface SafeVarargs {}", + }, + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " @SafeVarargs\n" + + " public X() { // Error, not varargs\n" + + " }\n" + + " @SafeVarargs\n" + + " public <T> X(T ... a) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public X() { // Error, not varargs\n" + + " ^^^\n" + + "@SafeVarargs annotation cannot be applied to fixed arity method X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337795 (make sure there is no warning if vararg parameter is reifiable) + public void test068() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + this.runConformTest( + new String[] { + "java/lang/SafeVarargs.java", + "package java.lang;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "import static java.lang.annotation.ElementType.CONSTRUCTOR;\n" + + "import static java.lang.annotation.ElementType.METHOD;\n" + + "\n" + + "@Retention(value=RUNTIME)\n" + + "@Target(value={CONSTRUCTOR,METHOD})\n" + + "public @interface SafeVarargs {}", + }, + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public <T> X(String ... a) {\n" + + " }\n" + + " public <T> X(int i, String ... a) {\n" + + " }\n" + + " public <T> List<T> asList(String ... a) {\n" + + " return null;\n" + + " }\n" + + " public <T> List<T> asList(Zork t, String ... a) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " public <T> List<T> asList(Zork t, String ... a) {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337795 (make sure there is a warning if vararg parameter is not reifiable) + public void test068b() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + this.runConformTest( + new String[] { + "java/lang/SafeVarargs.java", + "package java.lang;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "import static java.lang.annotation.ElementType.CONSTRUCTOR;\n" + + "import static java.lang.annotation.ElementType.METHOD;\n" + + "\n" + + "@Retention(value=RUNTIME)\n" + + "@Target(value={CONSTRUCTOR,METHOD})\n" + + "public @interface SafeVarargs {}", + }, + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public <T> X(T ... a) {\n" + + " }\n" + + " public <T> X(int i, T ... a) {\n" + + " }\n" + + " public <T> List<T> asList(T ... a) {\n" + + " return null;\n" + + " }\n" + + " public <T> List<T> asList(T t, T ... a) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public <T> X(T ... a) {\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter a\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " public <T> X(int i, T ... a) {\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter a\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " public <T> List<T> asList(T ... a) {\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter a\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " public <T> List<T> asList(T t, T ... a) {\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter a\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337795 + public void test068c() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + this.runConformTest( + new String[] { + "java/lang/SafeVarargs.java", + "package java.lang;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "import static java.lang.annotation.ElementType.CONSTRUCTOR;\n" + + "import static java.lang.annotation.ElementType.METHOD;\n" + + "\n" + + "@Retention(value=RUNTIME)\n" + + "@Target(value={CONSTRUCTOR,METHOD})\n" + + "public @interface SafeVarargs {}", + }, + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " @SafeVarargs\n" + + " public <T> X(T ... a) {\n" + + " }\n" + + " @SafeVarargs\n" + + " public <T> X(int i, T ... a) {\n" + + " }\n" + + " @SafeVarargs\n" + + " public <T> List<T> asList(T ... a) {\n" + + " return null;\n" + + " }\n" + + " @SafeVarargs\n" + + " public <T> List<T> asList(T t, T ... a) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " public <T> List<T> asList(T ... a) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "@SafeVarargs annotation cannot be applied to non-final instance method asList\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " public <T> List<T> asList(T t, T ... a) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "@SafeVarargs annotation cannot be applied to non-final instance method asList\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337795 + public void test068d() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + this.runConformTest( + new String[] { + "java/lang/SafeVarargs.java", + "package java.lang;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "import static java.lang.annotation.ElementType.CONSTRUCTOR;\n" + + "import static java.lang.annotation.ElementType.METHOD;\n" + + "\n" + + "@Retention(value=RUNTIME)\n" + + "@Target(value={CONSTRUCTOR,METHOD})\n" + + "public @interface SafeVarargs {}", + }, + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " @SafeVarargs\n" + + " public static <T> List<T> asList(T ... a) {\n" + + " return null;\n" + + " }\n" + + " public static <T> List<T> asList2(T ... a) {\n" + + " return null;\n" + + " }\n" + + " List<? extends Class<?>> classes; \n" + + " {\n" + + " classes = X.asList(String.class, Boolean.class);\n" + + " classes = X.asList2(String.class, Boolean.class);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " public static <T> List<T> asList2(T ... a) {\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter a\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " classes = X.asList2(String.class, Boolean.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Class<? extends Object&Serializable&Comparable<?>> is created for a varargs parameter\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=337795 (test effect of SuppressWarnings (should suppress at declaration site, but not at call site) + public void test068e() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + this.runConformTest( + new String[] { + "java/lang/SafeVarargs.java", + "package java.lang;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "import static java.lang.annotation.ElementType.CONSTRUCTOR;\n" + + "import static java.lang.annotation.ElementType.METHOD;\n" + + "\n" + + "@Retention(value=RUNTIME)\n" + + "@Target(value={CONSTRUCTOR,METHOD})\n" + + "public @interface SafeVarargs {}", + }, + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " @SafeVarargs\n" + + " public static <T> List<T> asList(T ... a) {\n" + + " return null;\n" + + " }\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public static <T> List<T> asList2(T ... a) {\n" + + " return null;\n" + + " }\n" + + " List<? extends Class<?>> classes; \n" + + " {\n" + + " classes = X.asList(String.class, Boolean.class);\n" + + " classes = X.asList2(String.class, Boolean.class);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 14)\n" + + " classes = X.asList2(String.class, Boolean.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Class<? extends Object&Serializable&Comparable<?>> is created for a varargs parameter\n" + + "----------\n"); + } } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java index df9b85f1e7..e648d88e2e 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java @@ -11876,7 +11876,7 @@ public void test0016() { .append("7717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839") .append("1840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119") .append("0219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964") - .append("19651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999null2001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620") + .append("1965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620") .append("2720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089") .append("2090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121") .append("5221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214") diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/CodeSnippetTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/CodeSnippetTest.java index a129c8309e..1b9a726a43 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/CodeSnippetTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/CodeSnippetTest.java @@ -43,6 +43,9 @@ private IRequestor getNoResultRequestor() { } }; } +static { +// TESTS_NAMES = new String[] {"testDiamond"}; +} public static Test suite() { return setupSuite(testClass()); } @@ -927,4 +930,24 @@ public void testBug345334() { }), "SUCCESS".toCharArray()); } +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=343693 + */ +public void testDiamond() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + return; + } + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class X<T> {", + " T field;", + " public X(T param) {", + " field = param;", + " }", + " public T foo() {", + " return field;", + " }", + "};", + "new X<>(\"SUCCESS\").foo();\n"}), + "SUCCESS".toCharArray()); +} } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/StandardVMLauncher.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/StandardVMLauncher.java index b91d279638..efd73b4a33 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/StandardVMLauncher.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/StandardVMLauncher.java @@ -100,9 +100,14 @@ public String[] getCommandLine() { } long vmVersion = Util.getMajorMinorVMVersion(); - if (vmVersion != -1 && vmVersion >= ClassFileConstants.JDK1_6) { - commandLine.addElement("-XX:-FailOverToOldVerifier"); - commandLine.addElement("-Xverify:all"); + if (vmVersion != -1) { + if (vmVersion >= ClassFileConstants.JDK1_6) { + commandLine.addElement("-XX:-FailOverToOldVerifier"); + commandLine.addElement("-Xverify:all"); + } + if (vmVersion >= ClassFileConstants.JDK1_7) { + commandLine.addElement("-XX:+UnlockExperimentalVMOptions"); + } } // debug mode |